【问题标题】:Proper way to make custom component containing other components制作包含其他组件的自定义组件的正确方法
【发布时间】:2019-03-28 18:09:47
【问题描述】:

我想制作自己的简单组件,其中包含其他组件。它看起来像:

TTag = class(TLayout)
private
    _line: TLine;
    _label: TLabel;
    _background: TRoundRect;
    _button: TLabel;
public
    constructor Create(AOwner: TComponent); override;
end;

当我将此组件放在表单上时,一切正常,我的表单结构如下所示:

但在 Delphi IDE 重新打开后,它看起来像:

如何添加子组件来避免这种奇怪的行为?

【问题讨论】:

  • 所有子组件只需设置 Stored := False

标签: delphi firemonkey custom-component


【解决方案1】:

这是SetSubComponent的典型案例:

调用 SetSubComponent 来表明这个组件是否是一个 子组件。子组件是其所有者是组件的组件 除了它所在的表单或数据模块。除非这样一个 组件调用 SetSubComponent 并将 IsSubComponent 设置为 True,它的 发布的属性不会保存到表单文件中。

对于您的每个子组件,在您的构造函数中调用SetSubComponent(True)

【讨论】:

    猜你喜欢
    • 2015-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-06
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多