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. Another approach is to use open array parameters.
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.