Quick start manual
6-12
Delphi Language Guide
Parameters
the = symbol and a default value. Parameter names must be valid identifiers. Any
declaration can be preceded by var, const, or out. Examples:
(X, Y: Real)
(var S: string; X: Integer)
(HWnd: Integer; Text, Caption: PChar; Flags: Integer)
(const P; I: Integer)
The parameter list specifies the number, order, and type of parameters that must be
passed to the routine when it is called. If a routine does not take any parameters, omit
the identifier list and the parentheses in its declaration:
procedure UpdateRecords;
begin
ƒ
end;
Within the procedure or function body, the parameter names (X and Y in the first
example) can be used as local variables. Do not redeclare the parameter names in the
local declarations section of the procedure or function body.
Parameter semantics
Parameters are categorized in several ways:
• Every parameter is classified as value, variable, constant, or out. Value parameters
are the default; the reserved words var, const, and out indicate variable, constant,
and out parameters, respectively.
• Value parameters are always typed, while constant, variable, and out parameters
can be either typed or untyped.
• Special rules apply to array parameters. See “Array parameters” on page 6-16.
Files and instances of structured types that contain files can be passed only as
variable (var) parameters.
Value and variable parameters
Most parameters are either value parameters (the default) or variable (var)
parameters. Value parameters are passed by value, while variable parameters are
passed by reference. To see what this means, consider the following functions.
function DoubleByValue(X: Integer): Integer; // X is a value parameter
begin
X := X * 2;
Result := X;
end;
function DoubleByRef(var X: Integer): Integer; // X is a variable parameter
begin
X := X * 2;
Result := X;
end;