开发数组,参数用const限定词,Slice为取部分长度的数组成员。也可以直接用 [] 的方式传参
代码如下:
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses System.Diagnostics, System.Math; type TDays = array of Integer; //函数定义 procedure ShowOpenArrays(const AArrayInt: array of Integer); var I: Integer; begin for I := Low(AArrayInt) to High(AArrayInt) do begin Form1.Memo1.Lines.Add('开放数组[' + I.toString + '] := ' + AArrayInt[I].toString); end; end; //计时 procedure TForm1.Button1Click(Sender: TObject); var m_ArrayInt: array[0..2] of Integer; begin m_ArrayInt[0] := 6; m_ArrayInt[1] := 8; m_ArrayInt[2] := 12; //Slice为取数组部分成员 ShowOpenArrays(Slice(m_ArrayInt, 2)); ShowOpenArrays([33,44,520]); end; end.