FMXEmbeddedForm (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search


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:



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


{$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);
  while AForm.ChildrenCount>0 do

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

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


See Also