How can I display a Delphi form in a panel?

大城市里の小女人 提交于 2019-12-21 23:17:52

问题


I've tried to follow the example of http://docwiki.embarcadero.com/CodeExamples/XE7/en/FMXEmbeddedForm_(Delphi) but I hit my first problem with the children of TCustomForm, which are apparently read only, so I commented that out and put in ArgForm.Parent:= ArgParent; instead, but I still just get an empty screen and can't see the buttons that are in my second form.

The code for my main form 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, Unit2;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    procedure FormCreate(Sender: TObject);
    procedure EmbedForm(ArgParent : TControl; ArgForm : TCustomForm);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Form2: TForm2;

implementation

{$R *.fmx}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Form2:= TForm2.Create(Self);
  EmbedForm(Panel1, Form2);
end;

procedure TForm1.EmbedForm(ArgParent: TControl; ArgForm: TCustomForm);
begin
  //while ArgForm.ChildrenCount>0 do
  //begin
    //ArgForm.Children[0]:= ArgParent);
  //end;
  ArgForm.Parent:= ArgParent;
end;
end.

The code for the form to put in the panel of my main form 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)
    Button1: TButton;
    Button2: TButton;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.fmx}

end.

回答1:


You just need to use the code exactly as it is written in the example. You wrote:

while ArgForm.ChildrenCount>0 do
  ArgForm.Children[0]:= ArgParent;

But the code in the example you linked to reads:

while ArgForm.ChildrenCount>0 do
  ArgForm.Children[0].Parent := ArgParent;

On the plus side, you have at least corrected the spelling of embed.



来源:https://stackoverflow.com/questions/28677586/how-can-i-display-a-delphi-form-in-a-panel

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