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

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

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;

相关文章:

  • 2022-12-23
  • 2021-09-12
  • 2022-01-04
  • 2022-12-23
  • 2022-02-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-04-29
  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案