?
Solved

Function VS Procedure

Posted on 2004-04-08
9
Medium Priority
?
155 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 60 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Loops Section Overview
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

839 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