Quick start manual
Procedures and functions
6-11
Parameters
in Unit1; if no routine in Unit1 matches the name and parameter list in the call, an
error results.
For information about distributing overloaded methods in a class hierarchy, see
“Overloading methods” on page 7-12. For information about exporting overloaded
routines from a shared library, see “The exports clause” on page 9-6.
Local declarations
The body of a function or procedure often begins with declarations of local variables
used in the routine’s statement block. These declarations can also include constants,
types, and other routines. The scope of a local identifier is limited to the routine
where it is declared.
Nested routines
Functions and procedures sometimes contain other functions and procedures within
the local-declarations section of their blocks. For example, the following declaration
of a procedure called DoSomething contains a nested procedure.
procedure DoSomething(S: string);
var
X, Y: Integer;
procedure NestedProc(S: string);
begin
ƒ
end;
begin
ƒ
NestedProc(S);
ƒ
end;
The scope of a nested routine is limited to the procedure or function in which it is
declared. In our example, NestedProc can be called only within DoSomething.
For real examples of nested routines, look at the DateTimeToString procedure, the
ScanDate function, and other routines in the SysUtils unit.
Parameters
Most procedure and function headers include a parameter list. For example, in the
header
function Power(X: Real; Y: Integer): Real;
the parameter list is (X: Real; Y: Integer).
A parameter list is a sequence of parameter declarations separated by semicolons and
enclosed in parentheses. Each declaration is a comma-delimited series of parameter
names, followed in most cases by a colon and a type identifier, and in some cases by