Quick start manual
Procedures and functions
6-17
Parameters
Note
The syntax of open array parameters resembles that of dynamic array types, but they 
do not mean the same thing. The previous example creates a function that takes any 
array of Char elements, including (but not limited to) dynamic arrays. To declare 
parameters that must be dynamic arrays, you need to specify a type identifier:
type TDynamicCharArray = array of Char;
function Find(A: TDynamicCharArray): Integer;
For information about dynamic arrays, see “Dynamic arrays” on page 5-20.
Within the body of a routine, open array parameters are governed by the following 
rules.
• They are always zero-based. The first element is 0, the second element is 1, and so 
forth. The standard Low and High functions return 0 and Length–1, respectively. 
The SizeOf function returns the size of the actual array passed to the routine.
• They can be accessed by element only. Assignments to an entire open array 
parameter are not allowed.
• They can be passed to other procedures and functions only as open array 
parameters or untyped var parameters. They cannot be passed to SetLength.
• Instead of an array, you can pass a variable of the open array parameter’s base 
type. It will be treated as an array of length 1.
When you pass an array as an open array value parameter, the compiler creates a 
local copy of the array within the routine’s stack frame. Be careful not to overflow the 
stack by passing large arrays.
The following examples use open array parameters to define a Clear procedure that 
assigns zero to each element in an array of reals and a Sum function that computes 
the sum of the elements in an array of reals.
procedure Clear(var A: array of Real);
var
I: Integer;
begin
for I := 0 to High(A) do A[I] := 0;
end;
function Sum(const A: array of Real): Real;
var
I: Integer;
S: Real;
begin
S := 0;
for I := 0 to High(A) do S := S + A[I];
Sum := S;
end;
When you call routines that use open array parameters, you can pass open array 
constructors to them. See “Open array constructors” on page 6-21.










