Link to home
Start Free TrialLog in
Avatar of cybermilky
cybermilky

asked on

Function VS Procedure

I'm confused between Function and Procedure. What are their difference?
ASKER CERTIFIED SOLUTION
Avatar of Russell Libby
Russell Libby
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shaneholmes
shaneholmes


//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

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

Better dbl-check your procedure again....

Russell


OOPS!

<SMILE>

Shane
Avatar of cybermilky

ASKER

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?
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?
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?
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
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