您的位置:首页 > 编程语言 > Delphi

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

2016-03-17 02:02 435 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: