Open array constructors allow you
to construct arrays directly within function and procedure calls. They can be
passed only as open array parameters or variant open array parameters.
An open array constructor, like a
set constructor, is a sequence of expressions separated by commas and enclosed
in brackets.
For example, given the
declarations
var I, J:
Integer;
procedure
Add(A: array of Integer);
you could call the Add procedure with
the statement
Add([5, 7, I, I + J]);
This is equivalent to
var Temp:
array[0..3] of Integer;
...
Temp[0] := 5;
Temp[1] := 7;
Temp[2] := I;
Temp[3] := I + J;
Add(Temp);
Open array constructors can be passed only as value or const parameters. The expressions in a constructor must be assignment-compatible with the base type of the array parameter. In the case of a variant open array parameter, the expressions can be of different types.
Calling procedures and functions
开放数组构造器允许在函数或过程调用中直接构造数组;它们仅用于传递开放数组参数或变体开放数组参数。
与集合构造器相似,开放数组构造器是一个由方括号封装、逗号隔开的表达式序列。
例如,对于如下声明
var I, J:
Integer;
procedure
Add(A: array of Integer);
可以用如下语句调用Add过程:
Add([5, 7, I, I + J]);
这等价于下列语句
var Temp:
array[0..3] of Integer;
...
Temp[0] := 5;
Temp[1] := 7;
Temp[2] := I;
Temp[3] := I + J;
Add(Temp);
开放数组构造器仅用于传递值参数或常量(const)参数。构造器中的表达式必需与开放数组参数的基类型是赋值兼容的。对于变体开放数组参数的情况,表达式可以是不同类型的。