Custom component controls keep re-creating

孤街浪徒 提交于 2019-12-02 03:13:00

问题


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

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.

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.

I'm using Delphi XE8 and Firemonkey.


回答1:


You need to set the stored property of your sub components to false.

paLaterale := TPanel.Create(Self);
paLaterale.Stored := false;
etc


来源:https://stackoverflow.com/questions/30912270/custom-component-controls-keep-re-creating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!