Solved

Function VS Procedure

Posted on 2004-04-08
9
146 Views
Last Modified: 2010-04-05
I'm confused between Function and Procedure. What are their difference?
0
Comment
Question by:cybermilky
  • 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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10789255
OOPS!

<SMILE>

Shane
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now