Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to know the form is shown with Show() or ShowModal()

My Environment: C++ Builder XE4

Is it possible for FormB to know FormB is shown with Show() or ShowModal()?

At FormA:

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

At FormB:

void __fastcall TFormB::FormShow(TObject *Sender)
{
   // with some if sentence to know Show() or ShowModal()
}
like image 516
sevenOfNine Avatar asked Oct 04 '15 03:10

sevenOfNine


Video Answer


1 Answers

You can test for fsModal in FormState at the onShowEvent of your form.

I've made you a small example:

Create a new project, and add an extra form to it. On the Main Form place two buttons, and let them display your 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 an 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.

like image 85
Jens Borrisholt Avatar answered Sep 19 '22 16:09

Jens Borrisholt