Quick start manual

6-16
Delphi Language Guide
Parameters
Array parameters
When you declare routines that take array parameters, you cannot include index type
specifiers in the parameter declarations. That is, the declaration
procedure Sort(A: array[1..10] of Integer); // syntax error
causes a compilation error. But
type TDigits = array[1..10] of Integer;
procedure Sort(A: TDigits);
is valid. For most purposes, however, open array parameters are a better solution.
Since the Delphi language does not implement value semantics for dynamic arrays,
"value" parameters in routines do not represent a full copy of the dynamic array. In
this example
type
TDynamicArray = array of Integer;
procedure p(Value: TDynamicArray);
begin
Value[0] := 1;
end;
procedure Run;
var
a: TDynamicArray;
begin
SetLength(a, 1);
a[0] := 0;
p(a);
Writeln(a[0]); // Prints "1"!
end;
Note that the assignment to Value[0] in routine p will modify the content of dynamic
array of the caller, despite Value being a by-value parameter. If a full copy of the
dynamic array is required, use the Copy standard procedure to create a value copy of
the dynamic array.
Open array parameters
Open array parameters allow arrays of different sizes to be passed to the same
procedure or function. To define a routine with an open array parameter, use the
syntax array of type (rather than array[X..Y] of type) in the parameter declaration.
For example,
function Find(A: array of Char): Integer;
declares a function called Find that takes a character array of any size and returns an
integer.