看看这个procedure TForm1.Button1Click(Sender: TObject); type TAI = array of integer; TAAI = array of TAI; var a: TAAI; n, m: integer; Str: string; begin setlength(a, 10); for n := low(a) to high(a) do begin SetLength(a[n], n + 1); for m := low(a[n]) to high(a[n]) do a[n][m] := m; end; for n := low(a) to high(a) do begin Str := ''; for m := low(a[n]) to high(a[n]) do Str := str + ', ' + IntToStr(a[n][m]); Memo1.Lines.Add(Str); end; end;
下面是delphi的帮助,当然你也可以用setlength(a,10,10)来分配内存 The following example uses dynamic arrays (and the IntToStr function declared in the SysUtils unit) to create a triangular matrix of strings.var A : array of array of string; I, J : Integer; begin SetLength(A, 10); for I := Low(A) to High(A) do begin SetLength(A[I], I); for J := Low(A[I]) to High(A[I]) do A[I,J] := IntToStr(I) + ',' + IntToStr(J) + ' '; end; end;
定义 arr: array of array of 类型 分配内存 SetLength(arr,x,y)//x,y为整数
type
TAI = array of integer;
TAAI = array of TAI;
var
a: TAAI;
n, m: integer;
Str: string;
begin
setlength(a, 10);
for n := low(a) to high(a) do
begin
SetLength(a[n], n + 1);
for m := low(a[n]) to high(a[n]) do
a[n][m] := m;
end; for n := low(a) to high(a) do
begin
Str := '';
for m := low(a[n]) to high(a[n]) do
Str := str + ', ' + IntToStr(a[n][m]);
Memo1.Lines.Add(Str);
end;
end;
The following example uses dynamic arrays (and the IntToStr function declared in the SysUtils unit) to create a triangular matrix of strings.var A : array of array of string;
I, J : Integer;
begin
SetLength(A, 10);
for I := Low(A) to High(A) do
begin
SetLength(A[I], I);
for J := Low(A[I]) to High(A[I]) do
A[I,J] := IntToStr(I) + ',' + IntToStr(J) + ' ';
end;
end;
arr: array of array of 类型
分配内存
SetLength(arr,x,y)//x,y为整数
继续设置SetLength(A, 15);
也可以