Reputation: 1519
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?
Upvotes: 0
Views: 1037
Reputation: 32344
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.
Upvotes: 8