如何在面板中显示 Delphi 表单?
How can I display a Delphi form in a panel?
我试着按照 http://docwiki.embarcadero.com/CodeExamples/XE7/en/FMXEmbeddedForm_(Delphi) 的例子,但我遇到了 TCustomForm 的子项的第一个问题,它们显然是只读的,所以我将其注释掉并放入 ArgForm.Parent:= ArgParent;
相反,但我仍然只是看到一个空白屏幕,看不到第二个表单中的按钮。
我的主窗体代码是:
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.
放置在我的主窗体面板中的窗体代码是:
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.
您只需要完全按照示例中编写的代码使用即可。您写道:
while ArgForm.ChildrenCount>0 do
ArgForm.Children[0]:= ArgParent;
但是您链接到的示例中的代码显示为:
while ArgForm.ChildrenCount>0 do
ArgForm.Children[0].Parent := ArgParent;
从好的方面来说,您至少更正了 embed 的拼写。
我试着按照 http://docwiki.embarcadero.com/CodeExamples/XE7/en/FMXEmbeddedForm_(Delphi) 的例子,但我遇到了 TCustomForm 的子项的第一个问题,它们显然是只读的,所以我将其注释掉并放入 ArgForm.Parent:= ArgParent;
相反,但我仍然只是看到一个空白屏幕,看不到第二个表单中的按钮。
我的主窗体代码是:
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.
放置在我的主窗体面板中的窗体代码是:
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.
您只需要完全按照示例中编写的代码使用即可。您写道:
while ArgForm.ChildrenCount>0 do
ArgForm.Children[0]:= ArgParent;
但是您链接到的示例中的代码显示为:
while ArgForm.ChildrenCount>0 do
ArgForm.Children[0].Parent := ArgParent;
从好的方面来说,您至少更正了 embed 的拼写。