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.
118
Parameters This topic covers the following items:
Parameter semantics
String parameters
Array parameters
Default parameters