我有以下的成分包含從自定義類衍生的特性:,不會出現在運行時
unit MyComponentTest3;
interface
uses Windows, ExtCtrls,Classes,Controls;
type
TMyClass3 = class
myString: string;
myNumber: double;
end;
TMyComponentTest3 = class(TCustomPanel)
private
FMyProperty: TMyClass3;
procedure SetMyProperty(Value: TMyClass3);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure SetMyPropertyPublic(AmyString: string; AmyNumber: double);
published
property MyProperty: TMyClass3 read FMyProperty write SetMyProperty;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('MyComponents', [TMyComponentTest3]);
end;
{ TMyComponentTest3 }
constructor TMyComponentTest3.Create(AOwner: TComponent);
begin
inherited;
FMyProperty:= TMyClass3.Create;
end;
destructor TMyComponentTest3.Destroy;
begin
FMyProperty.Free;
inherited;
end;
procedure TMyComponentTest3.SetMyProperty(Value: TMyClass3);
begin
with FMyProperty do
begin
myString:= Value.myString;
myNumber:= Value.myNumber;
end;
end;
procedure TMyComponentTest3.SetMyPropertyPublic(AmyString: string;
AmyNumber: double);
var
auxMyProperty: TMyClass3;
begin
auxMyProperty:= TMyClass3.Create;
with auxMyProperty do
begin
myString:= AmyString;
myNumber:= AmyNumber;
end;
SetMyProperty(auxMyProperty);
auxMyProperty.Free;
end;
end.
它工作正常,但是當我設置的值在設計階段的財產和運行程序的價值觀消失。如果我設置組件的值,保存所有內容並在加載值時不會再出現同樣的問題,如果我設置了組件的值,則不再存在...
我想問題是因爲我正在創建自定義類的實例時間,但我不確定,我不知道如何解決這個問題。有誰知道我能做什麼?
任何理由不做出'TMyClass3'記錄,而不是一類? –
這只是一個簡單的例子,在我的真實代碼中它更復雜... – Felipe
@J ...不管它有多複雜,關鍵的決定因素是你是否想要值或引用賦值語義。 –