var A: Array [0..10] of Integer;{定义静态数组}
procedure TForm1.Button1Click(Sender: TObject);
var i:Integer;
begin
Memo1.Clear;
for i:=Low(A) to High(A) do
begin
Randomize;
A[i] :=Random(100);
memo1.lines.add(inttostr(A[i] ));
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i:Integer;
begin
Memo1.Clear;
for i:=Low(A) to High(A) do
begin
Randomize;
A[i] :=Random(100);
memo1.lines.add(inttostr(A[i] ));
end;
end;
///////////////////////
var A: Array of Integer;{定义动态数组}
procedure TForm1.Button1Click(Sender: TObject);
var i:Integer;
begin
Memo1.Clear;
SetLength(A,10);{设置动态数组长度}
for i:=Low(A) to High(A) do
begin
Randomize;
A[i] :=Random(100);
memo1.lines.add(inttostr(A[i] ));
end;
A:=nil;{释放动态数组}
end;
procedure TForm1.Button1Click(Sender: TObject);
var i:Integer;
begin
Memo1.Clear;
SetLength(A,10);{设置动态数组长度}
for i:=Low(A) to High(A) do
begin
Randomize;
A[i] :=Random(100);
memo1.lines.add(inttostr(A[i] ));
end;
A:=nil;{释放动态数组}
end;
动态数组的释放
//动态数组一般是不需要手动释放的, 如果需要...
var
arr: array of Integer;
begin
{设置动态数组维数}
SetLength(arr,10);
{释放方法一}
arr := nil;
{释放方法二}
SetLength(arr, 0);
{释放方法三}
Finalize(arr);
end;