delphi 动态结构数组例程

本例程已经过验证,使用结构数组和指针的例子。

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 动态结构数组例程)