Quick start manual
6-2
Delphi Language Guide
Declaring procedures and functions
Declaring procedures and functions
When you declare a procedure or function, you specify its name, the number and
type of parameters it takes, and, in the case of a function, the type of its return value;
this part of the declaration is sometimes called the prototype, heading, or header. Then
you write a block of code that executes whenever the procedure or function is called;
this part is sometimes called the routine’s body or block.
Procedure declarations
A procedure declaration has the form
procedure procedureName(parameterList); directives;
localDeclarations;
begin
statements
end;
where procedureName is any valid identifier, statements is a sequence of statements
that execute when the procedure is called, and (parameterList), directives;, and
localDeclarations; are optional.
• For information about the parameterList, see “Parameters” on page 6-11.
• For information about directives, see “Calling conventions” on page 6-5, “Forward
and interface declarations” on page 6-6, “External declarations” on page 6-6,
“Overloading procedures and functions” on page 6-8, and “Writing dynamically
loadable libraries” on page 9-4. If you include more than one directive, separate
them with semicolons.
• For information about localDeclarations, which declares local identifiers, see “Local
declarations” on page 6-11.
Here is an example of a procedure declaration:
procedure NumString(N: Integer; var S: string);
var
V: Integer;
begin
V := Abs(N);
S := '';
repeat
S := Chr(V mod 10 + Ord('0')) + S;
V := V div 10;
until V = 0;
if N < 0 then S := '-' + S;
end;
Given this declaration, you can call the NumString procedure like this:
NumString(17, MyString);