3
Opa!
I have a question. How to know if a form assigned as a child of a TPanel
this fir?
My form is being created like this:
if not(Assigned(Form2)) then
begin
Form2 := TForm2.Create(self);
Form2.Parent := Panel1;
Form2.Show;
end;
The intention is to avoid Creating another instance of the same form. I’ve tried this, if not(Assigned(Form2)) then
and always says she’s not Assigned
and creates another form.
Source of the Unit1
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
type
TForm1 = class(TForm)
Panel: TPanel;
Button1: TButton;
Panel1: TPanel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses Unit2;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not(Assigned(Form2)) then
begin
Form2 := TForm2.Create(self);
Form2.Parent := Panel1;
Form2.Show;
end;
end;
end.
Source of the Unit2:
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
uses Unit1;
procedure TForm2.Button1Click(Sender: TObject);
begin
Close;
end;
end.
The Unit1 Source only changes that the Button
of the opening to Unit2
The FormStle
so much of Form2 as Form1 is set with fsNormal
.
You can show the class creation
TForm2
?– Junior Moreira
The creation is standard of Delphi not modified anything
– Edu Mendonça
Form2
is a public or local variable?– Junior Moreira
Old I went in New - VCL Application - Delphi which generated Unit1. Then I went to New - Vcl Form - Delphi which generated the Unit2, I put the two Buttons do not create anything Len of the two Processes. all there was standard of Delphi.
– Edu Mendonça