delphi 开放数组参数

在函数中如果数组的个数不定,可以使用开放数组参数

实参可以接受静态数组和动态数组

procedure p1(a:array of Byte);
begin

ShowMessage( IntToHex( Integer(@a),2));
ShowMessage(IntToStr(a[0]));
end;

procedure TForm1.btn1Click(Sender: TObject);
var
a:array[0..5] of Byte;
begin
ShowMessage(IntToHex( Integer(@a),2));
p1(a);
end;

procedure TForm1.btn2Click(Sender: TObject);
var
a:array of Byte;

begin
SetLength(a,10);
a[0]:=10;
ShowMessage(IntToHex( Integer(@a),2));
p1(a);
end;

经常使用的

array of const 类型的数组就能实现把不同类型、不同个数元素组成的数组一下子传递给例程。如下面Format 函数的定义:

function Format (const Format: string;

const Args: array of const): string;

原文地址:https://www.cnblogs.com/beeone/p/1812371.html