首页 > 编程语言 > 详细

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

时间:2016-03-17 07:02:48      阅读:218      评论:0      收藏:0      [点我收藏+]

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

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

原文:http://www.cnblogs.com/findumars/p/5285910.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!