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”变量? 谢谢。Delphi:如何从另一个父类访问Parent类中的变量?
德尔福2010年,印第安纳波利斯10,Win7的
叶氏,多数民众赞成freeking我出去: 您的文章没有什么太大的上下文解释代码段;请更清楚地解释你的情况。
您发布的任何代码都没有任何意义。你还没有创建'x'的实例,所以你当然不能从'y.test'访问它。另外,你的代码不会编译 - 带有'x(TList).F1.Clear'的行甚至不会通过编译器,更不用说任何方式的工作。请编辑您的帖子并添加**真实的**,可编译的代码来演示您正在尝试解决的问题。如果不是,我投票结束它作为“不是真正的问题”。 –
你需要使用getters和setter。如果它是java。这不是。我敢肯定,你的语言有类似的做法。 – 09182746
@DMPynes http://stackoverflow.com/questions/3963874/usage-of-property-vs-getters-setters-in-business-classes – waza123