我想通過指標訪問組件,而不是使用 FindComponent 進行搜索。以下分配適用于放置在表單上的組件,但不適用于動態創建的組件。例如:
var
Pbtn: ^TButton;
Button2: TButton;
begin
Pbtn := @Button1;
Showmessage(pbtn.caption); // works well
Button2 := TButton.Create(Form2);
Pbtn := @Button2;
Showmessage(pbtn.caption); // not work
...
uj5u.com熱心網友回復:
型別別是參考型別,因此型別別的物件實體已經表示為指標。不要使用^/@來參考這些物件(這只會參考指標本身,在大多數情況下很少需要),例如:
var
Pbtn: TButton;
Button2: TButton;
begin
Pbtn := Button1;
ShowMessage(pbtn.Caption); // works well
Button2 := TButton.Create(Form2);
Pbtn := Button2;
ShowMessage(pbtn.Caption); // also works well
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/439010.html
