views:

117

answers:

1

When form A is modal and it displays a second modal form B, and the modal result for B is set and B then closes, A is also closed.

How can this be prevented?

+8  A: 

This is not true, there has to be some other problem in your code. Setting ModalResult will affect only the currently modal form. Try this very simple example:

  • Create a new form

  • Drop a button onto it

  • In the button OnClick event handler add this code:

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      with TForm1.Create(Self) do begin
        if ShowModal = mrCancel then
          Self.Color := RGB(Random(256), Random(256), Random(256));
      end;
    end;
    

You will observe that each button press creates a new modal form, and you can repeat this as often as you wish. Closing a form will set its ModalResult to mrCancel and re-enable the parent form. To exit the application you will need to close all forms, one by one, in the opposite order of creation.

mghie
Correct, after some searching and testing I found that - wait for it - "somehow......" the button had a ModalResult of mrNo and after the second dialog closed, the right thing was done by the form class and the dialog was closed.
MX4399