【发布时间】:2011-12-06 22:49:32
【问题描述】:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdTCPClient;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
public
Flist : TList;
property list : TList read Flist write Flist;
end;
Tmy_class = class(TThread)
public
procedure test;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Tmy_class.test;
begin
// Error here, can't access the Flist var or list propertie, help !! How to access?
TForm1(TList).list.Clear;
// Error
Form1.list.Clear;
// Error
Form1.Flist.clear;
// HOW ????????
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Flist := FList.Create;
end;
end.
如何访问“Flist”变量? 谢谢。
德尔福 2010、印地 10、Win7
是的,这让我大开眼界: 您的帖子没有太多上下文来解释代码部分;请更清楚地解释您的情况。
【问题讨论】:
-
你需要使用getter和setter。如果是java。它不是。我确信你的语言有类似的方式来做类似的事情。
-
您发布的代码没有任何意义。你还没有创建
x的实例,所以你当然不能从y.test访问它。此外,您有无法编译的代码 -x(TList).F1.Clear的行甚至不会通过编译器,更不用说任何工作。请编辑您的帖子并添加真实的可编译代码,以演示您要解决的问题。如果不是,我投票决定将其关闭为“不是一个真正的问题”。 -
@waza - 你已经得到了帮助。阅读肯的评论。如果你有一个“x”的实例,你可以调用 someX.fl.Clear。
-
@Sertac Akyuz 我编辑了主代码,你能举个例子吗?