Solved

Function VS Procedure

Posted on 2004-04-08
9
151 Views
Last Modified: 2010-04-05
I'm confused between Function and Procedure. What are their difference?
0
Comment
Question by:cybermilky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
9 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 20 total points
ID: 10789134
A function returns a result value, a procedure does not

Regards,
Russell
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10789147

//As Russell stated, a function returns a result

function AbbreviateName(First, Last: String): String;
begin
  result:= First[1] + Last[1];
end;



var
 Abr: String;

 Abr:= AbbreviateName('SHane', 'Holmes');

Abr  = 'SH'



// and A Procedure does not return a result

procedure AbbreviateName(const First, Last: String): String;
var
begin
  ShowMesage(First[1] + Last[1]);
end;




Shane
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10789253

procedure AbbreviateName(const First, Last: String): String; <-- ????
var
begin
  ShowMesage(First[1] + Last[1]);
end;

Better dbl-check your procedure again....

Russell


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:shaneholmes
ID: 10789255
OOPS!

<SMILE>

Shane
0
 
LVL 1

Author Comment

by:cybermilky
ID: 10789284
function AbbreviateName(First, Last: String): String;
 - means this function returns the result value in String?

While the procedure will not return values, so end of the first line of procedure will not have the return type.

Am I correct?
0
 
LVL 1

Author Comment

by:cybermilky
ID: 10789285
function AbbreviateName(First, Last: String): String;
 - means this function returns the result value in String?

While the procedure will not return values, so end of the first line of procedure will not have the return type.

Am I correct?
0
 
LVL 1

Author Comment

by:cybermilky
ID: 10789288
function AbbreviateName(First, Last: String): String;
 - means this function returns the result value in String?

While the procedure will not return values, so end of the first line of procedure will not have the return type.

Am I correct?
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10789309
Like I said, functions return results, so for example:

function AbbreviateName(First, Last: String): String;

returns a string, and can be used like so:

var
 s: String;
begin
  s:=AbbreviateName('Foo', 'Bar');
  ShowMessage(s);
end;

And procedures are functions that do not return any results.

procedure AbbreviateName(First, Last: String);
begin
 ShowMessage(First+','+Last);
 // No result returned
end;

used like:

begin
  AbbreviateName('Foo', 'Bar');
end;

------------------

Regards,
Russell
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10790667
cybermilky,

 I believe Russell had already pinpointed by mistake. I had blocked and copied my function, pasted, and reedited it for the procedure, and didn't remove the string from the end, hense the OOPS post thereafter.

Shane

0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question