Quick start manual

Procedures and functions
6-3
Declaring procedures and functions
This procedure call assigns the value “17” to MyString (which must be a string
variable).
Within a procedure’s statement block, you can use variables and other identifiers
declared in the localDeclarations part of the procedure. You can also use the parameter
names from the parameter list (like N and S in the previous example); the parameter
list defines a set of local variables, so don’t try to redeclare the parameter names in
the localDeclarations section. Finally, you can use any identifiers within whose scope
the procedure declaration falls.
Function declarations
A function declaration is like a procedure declaration except that it specifies a return
type and a return value. Function declarations have the form
function functionName(parameterList): returnType; directives;
localDeclarations;
begin
statements
end;
where functionName is any valid identifier, returnType is a type identifier, statements is
a sequence of statements that execute when the function 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.
The function’s statement block is governed by the same rules that apply to
procedures. Within the statement block, you can use variables and other identifiers
declared in the localDeclarations part of the function, parameter names from the
parameter list, and any identifiers within whose scope the function declaration falls.
In addition, the function name itself acts as a special variable that holds the function’s
return value, as does the predefined variable Result.
As long as extended syntax is enabled ({$X+}), Result is implicitly declared in every
function. Do not try to redeclare it.
For example,
function WF: Integer;
begin
WF := 17;
end;