Is it possible to find out that the form is shown using Show () or ShowModal ()

My environment: C ++ Builder XE4

Is it possible for FormB to know that FormB is being displayed using Show () or ShowModal ()?

In FormA:

void __fastcall TFormA::Button1Click(TObject *Sender) { FormB->Show(); // FormB->ShowModal(); } 

In FormB:

 void __fastcall TFormB::FormShow(TObject *Sender) { // with some if sentence to know Show() or ShowModal() } 
+7
delphi c ++ builder
source share
1 answer

You can check fsModal in FormState for onShowEvent of your form.

I made you a small example:

Create a new project and add an additional form to it. Place two buttons on the main form and let them display the second form:

 uses Unit2; procedure TForm1.Button1Click(Sender: TObject); begin Form2.Show; end; procedure TForm1.Button2Click(Sender: TObject); begin Form2.ShowModal; end; 

No magic here: D

Then add OnShowEvent to your Form2 :

  procedure TForm2.FormShow(Sender: TObject); begin if fsModal in FormState then Caption := 'ShowModal' else Caption := 'Show'; end; 

That should do the trick for you.

+14
source share

All Articles