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