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.
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);
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.
Dostları ilə paylaş: