Reputation: 583
I am coding in Delphi 10. I have two forms: FormPrincipal
, which is the main form, and Formbanco
the one I want to call.
In FormPrincipal
I put a panel PanelCorpo
and I want to call Formbanco
and show it in the position of this panel.
I have tried two methods, but both did not work. See below:
FormPrincpal
calling Formbanco
using Showmodal
:// TActionlist OnExecute event
procedure TFormPrincipal.AbreFormBancoExecute(Sender: TObject);
begin
try
Application.CreateForm(Tformbanco,Formbanco);
Formbanco.Parent := PanelCorpo;
Formbanco.Align := alclient;
Formbanco.Showmodal;
finally
Freeandnil(formbanco);
end;
end;
The behavior was: it opened the called form Formbanco
properly, but frozen. Both forms did not allow to focus!
Show
:// TActionlist OnExecute event
procedure TFormPrincipal.AbreFormBancoExecute(Sender: TObject);
begin
try
Application.CreateForm(Tformbanco,Formbanco);
Formbanco.Parent := PanelCorpo;
Formbanco.Align := alclient;
Formbanco.Show;
finally
Freeandnil(formbanco);
end;
end;
The behaviour was: it blinks very quickly the Formbanco
, almost not visible, and continues in FormPrincipal
. I can't access Formbanco
!
I do appreciate help on this.
Upvotes: 1
Views: 4109
Reputation: 280
If you use TForm as a panel, don't do it. Create TFrame and include it as every component on your FormPrincipal.
If you want to include the content of a form on an other (inside a panel, a tabcontrol, ...) you can only do if you put a tpanel (or tlayer) as top level parent on the second form. When you want to include it on an other form change it's Parent property (and it's alignment if necessary). You don't have to show your second form in this case (but of course create it) : the panel/layout is on first one and showed on it.
Upvotes: -1
Reputation: 612794
A modal form can't be a child. So the second attempt using Show
is better. The mistake there is to destroy the form. Remember that Show
is asynchronous, so you destroy the form as soon as you create it. Don't do that. You will need to destroy it somewhere else, in response to another event. You will know what that should be.
The function should look like this:
procedure TFormPrincipal.AbreFormBancoExecute(Sender: TObject);
begin
Formbanco := Tformbanco.Create(Self);
Formbanco.Parent := PanelCorpo;
Formbanco.Align := alclient;
Formbanco.BorderIcons := [];
Formbanco.BorderStyle := bsNone;
Formbanco.Show;
end;
Upvotes: 3