FMXEmbeddedForm (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to embed one form inside another form by changing the Parent property of the components.

To build and test this example:

  • Create a Multi-Device Application - Delphi.
  • Add a second form to the project. Name the two forms ParentForm and EmbeddedForm. Make sure that the ParentForm is the last form created by the application. If the form to be embedded is added to the project by right-clicking Project1.exe in the Project Manager, go to the Project1.exe source and comment out or delete the line that creates the form to be embedded.
  • Add a TPanel on ParentForm.
  • Add different controls to EmbeddedForm. In this example there are two buttons and a TPanel.

The two forms should look like this:

ParentForm.png EmbeddedFormIMG.png

The result is:

ResultEmbeddedFormIMG.png

Code

Add the following code to the unit where the TParentForm class is defined.

implementation

{$R *.fmx}
 Uses unit2;

Add the following method to the TParentForm class.

// AParent can be any control, such as a panel or a tabsheet item of a TabControl.
procedure TParentForm.EmbeddForm(AParent:TControl; AForm:TCustomForm);
begin
  while AForm.ChildrenCount>0 do
    AForm.Children[0].Parent:=AParent;
end;

Add the following code to the OnCreate event handler of the ParentForm.

procedure TParentForm.FormCreate(Sender: TObject);
begin
  EmbeddForm(Panel1, TEmbeddedForm.Create(Self));
end;

Uses

See Also

Personal tools
Assistance