我怎樣才能動態值,我的組件的屬性變量德爾福組件屬性動態值
在我的部分,我有一個名爲ColorDefault領域,我希望能夠在程序中動態設置它的值。
原始代碼
var // global
_V_TB_DefaultColor: TColor
type
TMyClass = class
...
property ColorDefault: tcolor read _V_TB_DefaultColor write FDefaultColor;
//[dcc32 Error] MyButton.pas(85): E2168 Field or method identifier expected
...
end;
編輯:
我照下面所描述的湯姆但顏色沒有改變根據全局變量,顏色停留當它遵守作爲例如我的全球顏色是clyellow,我遵守我的組件,並將其放在窗體上,之後我將全局顏色變量更改爲clwhite,當我運行該程序時,它仍然是clyellow
type
TTestClass = class(TPanel)
private
{ Private declarations }
protected
{ Protected declarations }
FColorDefault:tcolor;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function GetGlobalColorVariable:TColor;
published
{ Published declarations }
property DefaultColor:TColor read GetGlobalColorVariable write FColorDefault;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('MyComponents', [TTestClass]);
end;
constructor TTestClass.Create(AOwner: TComponent);
begin
ColorInitiate;
inherited;
color:=DefaultColor;
end;
destructor TTestClass.Destroy;
begin
inherited;
end;
function TTestClass.GetGlobalColorVariable: TColor;
begin
result:=_V_TB_DefaultColor;
end;
end.
沒有多大意義在'FDefaultColor'字段中,如果你想從另一個變量 – MBo
中讀取屬性值,我看不到'ColorDefault'的任何屬性聲明,也沒有'_V_TB_DefaultColor'的任何聲明。請與您的標識符一致。這個問題與你最初提出的問題不同,並且變得一團糟。你讀過關於房產的文檔嗎?如果你想改變一個屬性,你必須爲它分配一個新的值。 –
如果您希望'ColorDefault'屬性發生變化,只需更改'_V_TB_DefaultColor',答案是否定的,否則不會發生,不存在這樣的automagic。我在我的回答中添加了一段關於此的內容。 –