Solved

Function VS Procedure

Posted on 2004-04-08
9
148 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 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