我想把 list 的 一组数,在 TreeView 中 表现出来,可是老是出错,大家来帮帮我啊~~~~代码如下:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;type
PMyList = ^AList;
AList = record
str: string;
sort: Integer;
pid: integer;
end; TForm1 = class(TForm)
TreeView1: TTreeView;
Button3: TButton;
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button3Click(Sender: TObject);
var
i: integer;
MyList: TList;
ARecord: PMyList;
TN : TTreeNode;begin for i:= 0 to 50 do
begin
ARecord^.sort := i + 1;
ARecord^.pid := i;
ARecord^.str := inttostr(i); TreeView1.Items.AddChild(TN,ARecord^.str[i]); Mylist.Move(i,i + 1);
end;end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;type
PMyList = ^AList;
AList = record
str: string;
sort: Integer;
pid: integer;
end; TForm1 = class(TForm)
TreeView1: TTreeView;
Button3: TButton;
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button3Click(Sender: TObject);
var
i: integer;
MyList: TList;
ARecord: PMyList;
TN : TTreeNode;begin for i:= 0 to 50 do
begin
ARecord^.sort := i + 1;
ARecord^.pid := i;
ARecord^.str := inttostr(i); TreeView1.Items.AddChild(TN,ARecord^.str[i]); Mylist.Move(i,i + 1);
end;end;
procedure TForm1.FormButton1Click(Sender: TObject);type
PMyList = ^AList;
AList = record
I: Integer;
C: Char;
end;var MyList: TList;
ARecord: PMyList;
B: Byte;
Y: Word;
begin
MyList := TList.Create;
try
New(ARecord);
ARecord^.I := 100;
ARecord^.C := 'Z';
MyList.Add(ARecord); {Add integer 100 and character Z to list}
New(ARecord);
ARecord^.I := 200;
ARecord^.C := 'X';
MyList.Add(ARecord); {Add integer 200 and character X to list} { Now paint the items onto the paintbox}
Y := 10; {Variable used in TextOut function} for B := 0 to (MyList.Count - 1) do
begin
ARecord := MyList.Items[B];
Canvas.TextOut(10, Y, IntToStr(ARecord^.I)); {Display I}
Y := Y + 30; {Increment Y Value again}
Canvas.TextOut(10, Y, ARecord^.C); {Display C}
Y := Y + 30; {Increment Y Value}
end; { Cleanup: must free the list items as well as the list }
for B := 0 to (MyList.Count - 1) do
begin ARecord := MyList.Items[B];
Dispose(ARecord);
end;
finally
MyList.Free;
end;
end;
不就是Delphi help 里面的的例子吗??