请问一个DELPHI 自定义数据结构的问题

来源:百度知道 编辑:UC知道 时间:2024/07/07 02:13:16
Delphi 7 自己声明一个数据结构如下
TMyFileList = class //不用class,用record也不行
Filelist,DirectoryList: TListbox;
end;
定义
temp1: TMyFileList;
使用
temp1.Filelist.Items.Add('fdjkslasfd');
结果出错,好像是不能写,哪位高人能指点一下
wind 你好,谢谢你的回答,但问题不在这,TListbox不用定义.
我发现是定义全局变量的时候出错,
我定义一个全局变量就会出问题.
var
Form1: TForm1;
//在此处定义全局变量,定义一个integer变量没有问题,
//但是这样就有问题,比如
MyListBox1: TListbox;//MyListBox1就无法使用
implementation

{$R *.dfm}

请问我要定义一个全局的TListBox,怎么定义,谢谢

TMyFileList = class //不用class,用record也不行
Filelist,DirectoryList: TListbox;
constructor Create;virtual;//类里用到别的类,需要自己重载构造函数和析构函数
destructor Destroy; override;
end;

var
Form1: TForm1;
temp1: TMyFileList;
implementation

{$R *.dfm}
constructor TMyFileList.Create;
begin
inherited Create;
FileList:=TListBox.Create(nil);
DirectoryList:=TListBox.Create(nil);
end;
destructor TMyFileList.Destroy;
begin
inherited;
FileList.Free;
DirectoryList.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);//测试自定义类
begin
temp1:=TMyFileList.Create;
temp1.Filelist.Parent:=Form1;//parent负责显示
temp1.DirectoryList.Parent:=Form1;
temp1.Filelist.Items.Add('fdjkslasfd');
showmessage(temp1.Filelist.Items[0]);
temp1.Free;
end;

-----------------------
Record 自定义结构,成员不能是对象
TMyFileList = class //不用class,用recor