(火猴,XE7) 我有一个以TTextControl为祖先的组件,引入了SizeConstraints,只是基于VCL版本。 设计器不会将约束属性保存到 .FMX 文件中。 当我查看“以文本形式查看表单”时,即使我之前编辑了属性值,约束也不存在(是的,我可以在对象检查器中编辑它,但它没有保存) 这段代码有什么问题?
约束定义:
TSizeConstraints = class(TObject)
...
published
...
property MaxHeight: Single index 0 read FMaxHeight write SetConstraints;
property MaxWidth: Single index 1 read FMaxWidth write SetConstraints;
...
end;
组件定义:
...
published
property Constraints : TSizeConstraints read FConstraints write SetConstraints;
...
procedure TMyComponent.SetConstraints(const Value: TSizeConstraints);
begin
FConstraints.Assign(Value);
end;
并且 TSizeConstraints.Assign 确实复制数据:
procedure TSizeConstraints.Assign( const C : TSizeConstraints );
begin
if Assigned( C ) then
begin
FMinHeight := C.FMinHeight;
FMaxHeight := C.FMaxHeight;
FMinWidth := C.FMinWidth;
FMaxWidth := C.FMaxWidth;
Change;
end;
end;
我错过了什么,还是 IDE 错误?
最佳答案
问题在于您是从 TObject
派生的。从TComponent
派生此类以获得流功能。或者也许像@NGLN 所建议的那样TPercient
。
您还应该更改您的Assign
方法以覆盖TPercient
中引入的虚拟Assign
。
关于delphi - 为什么 Delphi 不保存自定义组件的嵌套属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28459375/