自定义组件控件不断重新创建 [英] Custom component controls keep re-creating
问题描述
我是Firemonkey /自定义控件的新手,所以很抱歉,如果这是一个平凡的问题或重复的问题,但我被困住了,无法解决。
I'm a newbie in Firemonkey/custom controls so sorry if this is a banal question or a duplicate one but I'm stuck and can't figure it out.
这是我的自定义控件的代码
Here's the code of my custom control
unit swScheduler;
interface
uses
System.SysUtils, System.Classes, FMX.Types, FMX.Controls, FMX.StdCtrls,
FMX.Calendar, FMX.Objects;
type
TswScheduler = class(TControl)
private
{ Private declarations }
paLaterale: TPanel;
clCalendario: TCalendar;
paLibero: TPanel;
paScheduler: TPanel;
rcSCTop: TRectangle;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create( AOwner: TComponent ); override;
destructor Destroy; override;
published
{ Published declarations }
property Align default TAlignLayout.None;
property Enabled;
property Left;
property Top;
property Width;
property Height;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('CustomControls', [TswScheduler]);
end;
{ TswScheduler }
constructor TswScheduler.Create( AOwner: TComponent );
begin
inherited;
Self.Width := 650;
Self.Height := 400;
paLaterale := TPanel.Create( Self );
paLaterale.Parent := Self;
paLaterale.Align := TAlignLayout.Left;
paLaterale.Width := 202;
clCalendario := TCalendar.Create( Self );
clCalendario.Parent := paLaterale;
clCalendario.Align := TAlignLayout.Top;
paLibero := TPanel.Create( Self );
paLibero.Parent := paLaterale;
paLibero.Align := TAlignLayout.Client;
paScheduler := TPanel.Create( Self );
paScheduler.Parent := Self;
paScheduler.Align := TAlignLayout.Client;
rcSCTop := TRectangle.Create( Self );
rcSCTop.Parent := paScheduler;
rcSCTop.Align := TAlignLayout.Top;
rcSCTop.Height := 100;
end;
destructor TswScheduler.Destroy;
begin
inherited;
end;
initialization
RegisterClass( TswScheduler );
end.
它编译时没有错误,但我的问题是何时要使用它。
It compiles without errors but my problem is when I want to use it.
我在设计时将其放置在表单上而没有问题/错误
I drop it on a form at design time without problems/errors
但是当我运行应用程序时,它会这样做
but when I run the application it does this
如果我关闭并重新在IDE中打开pas文件
and if I close and re-open the pas file in the IDE it does the same thing
,并且在运行应用程序时...
and when running the app...
就像它一次又一次地构造函数一样。
Like if it does the constructor again and again.
我在Google上进行了搜索,但找不到关于firemonkey的类似信息。
I searched on Google but could'f find something like this about firemonkey.
我尝试更改某些内容,但无法
I tried to change something but couldn't make it work.
任何提示都值得赞赏。
Any tips is appreciated. Thanks in advance.
我正在使用Delphi XE8和Firemonkey。
I'm using Delphi XE8 and Firemonkey.
推荐答案
您需要设置已存储属性
paLaterale := TPanel.Create(Self);
paLaterale.Stored := false;
etc
这篇关于自定义组件控件不断重新创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!