如何使用Firemonkey TPopUp制作自己的对话框组件? [英] How to make my own dialog component from Firemonkey TPopUp?

查看:109
本文介绍了如何使用Firemonkey TPopUp制作自己的对话框组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[Delphi XE5 Up2]

[Delphi XE5 Up2]

我尝试使用TPopUp继承和创建组件,遵循与CalendarFlyout的Flyouts演示中公开的相同的想法.我将不使用日历,但我希望该空间可用,以便放置所需的任何其他FMX组件.

I am trying to use TPopUp to inherit and create a component, following the same idea as exposed on the Flyouts demo for the CalendarFlyout. I will be not using the Calendar, but I want that space free so that I can place any other FMX component that I want.

我已经使用新的组件向导制作了该组件,并添加了一些控件:

I have made the component using the new component wizard and added some controls:

unit PopupTest;

interface

uses
  System.SysUtils, System.Classes, FMX.Types, FMX.Controls,
  FMX.Layouts, FMX.StdCtrls;

type
  TPopupTest = class(TPopup)
  private
    FPanel        : TPanel;
    FLayoutButton : TLayout;
    FCloseButton  : TButton;
    FSaveButton   : TButton;
    FClientArea   : TLayout;
  protected
    procedure   OnClose(Sender: TObject);
    procedure   OnSave(Sender: TObject);
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
  published
    { Published declarations }
  end;

procedure Register;

implementation

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

{ TPopupTest }

constructor TPopupTest.Create(AOwner: TComponent);
begin
  inherited;

  FPanel                   := TPanel.Create(self);
  FPanel.Position.X        := 0;
  FPanel.Position.Y        := 0;
  FPanel.Margins.Left      := 10;
  FPanel.Margins.Right     := 10;
  FPanel.Margins.Top       := 10;
  FPanel.Margins.Bottom    := 10;
  FPanel.StyleLookup       := 'flyoutpanel';
  FPanel.Align             := TAlignLayout.alClient;
  FPanel.Visible           := True;

  FLayoutButton            := TLayout.Create(FPanel);
  FLayoutButton.Align      := TAlignLayout.alBottom;
  FLayoutButton.Height     := 22;

  FCloseButton             := TButton.Create(FLayoutButton);
  FCloseButton.Align       := TAlignLayout.alLeft;
  FCloseButton.StyleLookup := 'flyoutbutton';
  FCloseButton.Text        := 'Fechar';
  FCloseButton.OnClick     := OnClose;

  FSaveButton              := TButton.Create(FLayoutButton);
  FSaveButton.Align        := TAlignLayout.alLeft;
  FSaveButton.StyleLookup  := 'flyoutbutton';
  FSaveButton.Text         := 'Salvar';
  FSaveButton.OnClick      := OnSave;

  FClientArea              := TLayout.Create(FPanel);
  FClientArea.Align        := TAlignLayout.alClient;

  Width                    := 100;
  Height                   := 100;
end;

destructor TPopupTest.Destroy;
begin
  FClientArea.Free;
  FCloseButton.Free;
  FSaveButton.Free;
  FLayoutButton.Free;
  FPanel.Free;

  inherited;
end;

procedure TPopupTest.OnClose(Sender: TObject);
begin

end;

procedure TPopupTest.OnSave(Sender: TObject);
begin

end;

end.

我进行了几次测试,没有任何显示,只是弹出窗口本身,内部没有任何内容.我使用的是MetropoliUI样式,内部控件的组件上的样式均基于该样式.

I have made several tests and nothing appears, just the popup itself, nothing inside. I am using the MetropoliUI style and the Styles on the component for the inner controls are based on that style.

为简单起见,我删除了所有其他内容并进行了编译和测试.

For simplicity I have remove everything else and compiled and tested.

出于某些原因,我正在使用TPopUp,但是主要的原因是我的对话框"将插入到表单中,并且我将在其中添加一些TEdit,它们将通过LiveBinding连接到相同的DataSet等上.形式.因此,无需创建具有其他所有内容的另一种表单,并保留所有上下文(至少我认为这是正确的选择)

I am using the TPopUp for several reasons, but the main one is that my "dialog" will be inserted on the form, and I will add to it some TEdits that will be connected by LiveBinding to the same DataSet etc on the form. So no need to create another form with everything else, and preserve all the context (at least I believe this is the right thing to do)

我在寻找什么

  • 缺少什么使所有内部控件都出现
  • 如何确保用户可以在FClientArea(即TLayout)上添加其他控件?

最终结果是这样的:

The final result would like this:

在中间区域是一个TLayout,我可以在其中放置其他控件,例如TEdit.

Where in the middle area is a TLayout where I could drop other controls like TEdit.

推荐答案

当您在表单中创建TPopupTest时,必须将创建者的所有者和父项设置为您的Form.

When you create the TPopupTest in your form you have to set the creator's owner to your Form, as well as the Parent.

将单元更改为类似的外观会使其出现,但它并不完全符合您的想象,因此您必须对其进行一些改进.另外,我的解决方案可能不是最好的,但至少您现在会看到一些东西.

Changing the Unit to something like this will make it appear but it's not exactly as you picture it, you will have to refine it a bit. Also my solution might not be the best but at least you will get to see something now.

constructor TPopupTest.Create(AOwner: TComponent);
var
PopPanel: TPanel;
PopLayout: TLayout;
PopClose: TButton;
PopSave: TButton;
PopClientArea: TLayout;
begin
  inherited;

  PopPanel                   := TPanel.Create(Owner);
  PopPanel.Position.X        := 0;
  PopPanel.Position.Y        := 0;
  PopPanel.Margins.Left      := 10;
  PopPanel.Margins.Right     := 10;
  PopPanel.Margins.Top       := 10;
  PopPanel.Margins.Bottom    := 10;
  PopPanel.StyleLookup       := 'flyoutpanel';
  PopPanel.Parent            := Owner as TFmxObject;
  PopPanel.Align             := TAlignLayout.alClient;
  PopPanel.Visible           := True;

  PopLayout            := TLayout.Create(Owner);
  PopLayout.Parent     := PopPanel;
  PopLayout.Align      := TAlignLayout.alBottom;
  PopLayout.Height     := 22;

  PopClose             := TButton.Create(Owner);
  PopClose.Parent      := PopLayout;
  PopClose.Align       := TAlignLayout.alLeft;
  PopClose.StyleLookup := 'flyoutbutton';
  PopClose.Text        := 'Fechar';
  PopClose.OnClick     := OnClose;

  PopSave              := TButton.Create(Owner);
  PopSave.Parent       := PopLayout;
  PopSave.Align        := TAlignLayout.alLeft;
  PopSave.StyleLookup  := 'flyoutbutton';
  PopSave.Text         := 'Salvar';
  PopSave.OnClick      := OnSave;

  PopClientArea              := TLayout.Create(Owner);
  PopClientArea.Parent       := PopPanel;
  PopClientArea.Align        := TAlignLayout.alClient;

  FPanel:= PopPanel;
  FLayoutButton:= PopLayout;
  FSaveButton:= PopSave;
  FCloseButton:= PopClose;
  FClientArea:= PopClientArea;

  Width                    := 100;
  Height                   := 100;
end;

这篇关于如何使用Firemonkey TPopUp制作自己的对话框组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆