在firemonkey中创建复合控件

时间:2016-03-29 19:46:10

标签: delphi firemonkey

Delphi XE-6

我正在尝试创建自己的自定义Firemonkey控件,该控件派生自TGroupBox,我在组框中创建TGridPanelLayout控件。

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

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

1 个答案:

答案 0 :(得分:4)

您需要为您在设计时不想选择的每个子控件设置Stored属性为false。例如,以下代码创建了一个包含两个子控件的面板,TEditTButton

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.