How embed a firemonkey form inside a control?

主宰稳场 提交于 2019-11-30 14:18:57

The secret is in how you design your child form.

You need to create a control as a container, say a TLayout (no styling), TRectangle (Basic styling) or TPanel. I'd go with the TLayout. Decide on a name for your container, say 'Container' for the sake of argument. Now create you child form and simply assign the Parent of Container to your parent object.

So, from your code above (I'm assuming TControlView is your child form):

procedure TfrmMain.FormCreate(Sender: TObject);
var
  Control:TControlView;
begin
  Control := TControlView.Create(Self);
  Control.Container.parent := ListControls;
  Control.Container.width := 800;
end;
nexial

You have to set the container control's ClipChildren property to true.

yonojoy

Here is a step by step instruction:

  1. Design your embedded form. Place a TLayout with alignment alClient onto your form. Place all controls inside this layout:

    TFormEmbedded = class(TForm)
        LayoutMain: TLayout;
        //....
    end;
    
  2. Design your master form.

  3. Place a Layout onto your master form, that shall later contain the subform.

  4. Add the following code to FormCreate of your master form:

    procedure TFormMaster.FormCreate(Sender: TObject);
    var
        SubForm: TFormEmbedded;
    begin
        SubForm := TFormEmbedded.Create(Self);
        SubForm.LayoutMain.Parent := Self.LayoutSubForm;
    end;
    

Thanks to nexial for the original description.

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