在 firemonkey 中创建复合控件

creating composite controls in firemonkey

Delphi XE-6

我正在尝试创建我自己的从 TGroupBox 派生的自定义 Firemonkey 控件,我在组框上创建了一个 TGridPanelLayout 控件。

constructor TMyRadioGroup.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FLayout:= TGridPanelLayout.Create(self);
  FLayout.Parent:= self;
end;

如何阻止用户select 和/或删除 TGridPanelLayout 控件?在设计时,我只希望我的父控件(派生自 TGroupbox)可以 select-able 并且可以从表单中删除。

您需要为每个您不想在设计时选择的子控件设置 Stored 属性 到 false。例如,下面的代码创建了一个带有两个子控件的面板,一个 TEdit 和一个 TButton.

unit PanelCombo;

interface

uses
  System.SysUtils, System.Classes, FMX.Types, FMX.Controls,
  FMX.Controls.Presentation, FMX.StdCtrls, FMX.Edit;

type
  TPanelCombo = class(TPanel)
  private
    { Private declarations }
    edit1: TEdit;
    button1: TButton;
  protected
    { Protected declarations }
  public
    { Public declarations }
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
  published
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TPanelCombo]);
end;

constructor TPanelCombo.Create(AOwner: TComponent);
begin
  inherited;
  edit1:= TEdit.create(self);
  edit1.parent:= self;
  edit1.align:= TAlignLayout.Top;
  edit1.stored:= false;

  button1:= TButton.create(self);
  button1.parent:= self;
  button1.align:= TAlignLayout.bottom;
  button1.stored:= false;
end;

destructor TPanelCombo.Destroy;
begin
  inherited;
  edit1.Free;
  button1.Free;
end;

end.