-2
I have a FormPrincipal
which has a Tmenu
with Tactionlist
and from this form I want to call several other Forms, according to the menu items.
In the main form, I have a Panel
and I want the others to open inside this panel.
I adjusted the code below, after help from other colleagues of Stackoverflow in English, and it worked:
procedure TFormPrincipal.AbreFormBancoExecute(Sender: TObject);
begin
Formbanco := Tformbanco.Create(Self);
Formbanco.Parent := PanelCorpo;
Formbanco.Align := alclient;
Formbanco.BorderIcons := [];
Formbanco.BorderStyle := bsNone;
Formbanco.Show;
end;
But now I need to know which form is active in the Panel to be able to close it once I close the other, IE, I need to modify the above routine :
procedure TFormPrincipal.AbreFormBancoExecute(Sender: TObject);
begin
// identificar qual form está ativo dentro do FormPrincipal
// fechar este form e em seguida rodar o código abaixo
Formbanco := Tformbanco.Create(Self);
Formbanco.Parent := PanelCorpo;
Formbanco.Align := alclient;
Formbanco.BorderIcons := [];
Formbanco.BorderStyle := bsNone;
Formbanco.Show;
end;
This is a good approach to handling Forms calls from a correct main form?
. Adjust the code to get the currently open form. In Formbanco I put the following :
procedure TFormbanco.FormShow(Sender: TObject);
begin
Edit1.text := Screen.Activeform.Name; // não mostra Formbanco !!
// só mostra FormPrincipal !!
end;
Junior, thank you very much. But I still have a question, because the main point is to know which Forms is open on the screen, with the focus on it, at the moment I will open another Forms. I need to find this Forms open before opening a new one with Button1 or Button2 above. if Assigned() tells me which one is currently open?
– JRG
I will modify the answer complementing... In case we go through the Panel Children components to know which are forms and which close!
– Junior Moreira
Why not create a simple variable with the last form loaded?
– Tiago Rodrigues
Actually the best option for him is a
ShowModal
, let’s wait for his reaction to reading here.– Junior Moreira
Junio and Tiago, thank you. in the code above, when replacing Form.Show or Form.showmodal the application is locked after pressing Button2, because it opens Form2 but I do not change the focus for it and does not return to the main Form1 ! James, I thought and use this variable to store the last loaded form, that’s why I asked for help to get the name of the Visible form at the time. I adjusted the code by placing in the Onshow event of Forms that was opened Edit1.text := Screen.Activeform.Name , BUT IT DIDN’T WORK, as it always keeps the name of the Main form !!
– JRG
Guys, I’d appreciate it if you could see my latest code.
– JRG