----赖格英-----

记忆不好了,记录工作中的点点滴滴....

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
//这段代码在Delphi 2007和delphi 7下是可以执行的,所以正确使用结构体数组和指针应该是这样的,已验证

unit
Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); type TMyType = record S: String; I: Integer; end; TMyArray = array of TMyType; PMyArray = ^TMyArray; var MyArray: PMyArray; i:integer; AList:TStrings; begin try new(MyArray); AList:=TStringList.Create; SetLength(MyArray^, 50000); for i:=0 to 49999 do begin MyArray^[i].S :='中山'+inttostr(i); myArray^[i].I :=i; AList.Add(MyArray^[i].S+',年龄为:'+inttostr(MyArray^[i].I)); end; self.Memo1.Lines:=Alist; finally SetLength(MyArray^, 0); Dispose(MyArray); end; end; end.

这段代码在Delphi 2007和delphi 7下是可以执行的,所以正确使用结构体数组和指针应该是这样的,已验证。

 

posted on 2013-08-28 11:54  向北方  阅读(2913)  评论(0编辑  收藏  举报