Delphi动态申请数组内存的方法,不使用SetLength,采用和C相似的方式

procedure TForm1.Button1Click(Sender: TObject);

type

TArr = array [0..0] of Integer;

PArr = ^TArr;

var

arr: PArr;

i: Integer;

begin

GetMem(arr, 100);

for i := 0 to 100 - 1 do

arr[i] := i;

for i := 0 to 100 - 1 do

OutputDebugString(PChar(Format('%d'#13, [arr[i]])));

FreeMem(arr);

end;

procedure TForm1.Button2Click(Sender: TObject);

type

TArr = array [0..0,0..0] of Integer;

PArr = ^TArr;

var

arr: PArr;

i, j: Integer;

begin

GetMem(arr, 100);

for i := 0 to 10 - 1 do

for j := 0 to 10 - 1 do

arr[i][j] := i * j;

for i := 0 to 10 - 1 do

for j := 0 to 10 - 1 do

OutputDebugString(PChar(Format('%d', [arr[i][j]])));

FreeMem(arr);

end;

http://blog.csdn.net/henreash/article/details/14452327