Quick start manual
6-20
Delphi Language Guide
Default parameters and overloaded routines
If you use default parameter values in an overloaded routine, avoid ambiguous
parameter signatures. Consider, for example, the following.
procedure Confused(I: Integer); overload;
ƒ
procedure Confused(I: Integer; J: Integer = 0); overload;
ƒ
Confused(X); // Which procedure is called?
In fact, neither procedure is called. This code generates a compilation error.
Default parameters in forward and interface declarations
If a routine has a forward declaration or appears in the interface section of a unit,
default parameter values—if there are any—must be specified in the forward or
interface declaration. In this case, the default values can be omitted from the defining
(implementation) declaration; but if the defining declaration includes default values,
they must match those in the forward or interface declaration exactly.
Calling procedures and functions
When you call a procedure or function, program control passes from the point where
the call is made to the body of the routine. You can make the call using the routine’s
declared name (with or without qualifiers) or using a procedural variable that points
to the routine. In either case, if the routine is declared with parameters, your call to it
must pass parameters that correspond in order and type to the routine’s parameter
list. The parameters you pass to a routine are called actual parameters, while the
parameters in the routine’s declaration are called formal parameters.
When calling a routine, remember that
• expressions used to pass typed const and value parameters must be assignment-
compatible with the corresponding formal parameters.
• expressions used to pass var and out parameters must be identically typed with
the corresponding formal parameters, unless the formal parameters are untyped.
• only assignable expressions can be used to pass var and out parameters.
• if a routine’s formal parameters are untyped, numerals and true constants with
numeric values cannot be used as actual parameters.
When you call a routine that uses default parameter values, all actual parameters
following the first accepted default must also use the default values; calls of the form
SomeFunction(,,X) are not legal.