This is a continuation of my question: How can I display a Delphi form in a panel?
I want to use a forms global variable to embed it in a panel to display it now, but it only creates the form to embed, without it’s buttons.
In the code of the executable I’m creating the form to embed first and the form that I want to embed it in second, like so:
program Project1;
uses
System.StartUpCopy,
FMX.Forms,
Unit1 in ‘Unit1.pas’ {Form1},
Unit2 in ‘Unit2.pas’ {Form2};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm2, Form2);
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
The main form’s code is:
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Panel1: TPanel;
procedure EmbedForm(ArgParent : TControl; ArgForm : TCustomForm);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
uses Unit2;
procedure TForm1.FormCreate(Sender: TObject);
begin
EmbedForm(Panel1, Form2);
end;
procedure TForm1.EmbedForm(ArgParent: TControl; ArgForm: TCustomForm);
begin
while ArgForm.ChildrenCount>0 do
begin
ArgForm.Children[0].Parent:= ArgParent;
end;
end;
end.
The code of the form to embed is:
unit Unit2;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls;
type
TForm2 = class(TForm)
Button2: TButton;
Button1: TButton;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.fmx}
end.