我有一个自定义组件,在设计时可以创建这样的子组件:
constructor TALRectangle.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fShadow := TalShadow.Create;
fShadow.OnChanged := ShadowChanged;
end;
procedure TALRectangle.ShadowChanged(Sender: TObject);
begin
...
if shadow.enabled then begin
fShadowEffect := TshadowEffect.Create(self);
fShadowEffect.Parent := self;
end;
...
end;
问题是我将以dfm / fmx形式:
object ALRectangle1: TALRectangle
shadow.enabled = True
object TShadowEffect
Softness = 0.500000000000000000
Opacity = 1.000000000000000000
ShadowColor = x96000000
end
end
但我不希望在dfm / fmx表单中有关于TShadowEffect的任何内容,因为我动态创建并初始化此对象。
怎么办?
答案 0 :(得分:7)
有两种方法可以解决这个问题:
只需在设计时不创建TShadowEffect
对象即可:
procedure TALRectangle.ShadowChanged(Sender: TObject);
begin
...
if fShadow.Enabled and not (csDesigning in ComponentState) then begin
fShadowEffect := TShadowEffect.Create(Self);
fShadowEffect.Parent := Self;
end;
...
end;
如果您必须创建它,请将其Stored
属性设置为false:
procedure TALRectangle.ShadowChanged(Sender: TObject);
begin
...
if fShadow.Enabled then begin
fShadowEffect := TShadowEffect.Create(Self);
fShadowEffect.Parent := Self;
fShadowEffect.SetSubComponent(True);
fShadowEffect.Stored := False;
end;
...
end;