Reto Höhener
Reto Höhener

Reputation: 5808

Wizard style: How to close the current modal dialog and open the next modal dialog in the button handler?

My application has an administration dialog that can be reached via a login dialog (both modal).

On the login dialog, the user enters his password, then clicks ok. In the ok button handler, I am calling Self.Close(), then AdminForm.ShowModal().

The problem is that the LoginForm remains open behind the AdminForm until the call to AdminForm.ShowModal() returns (visible when you move the AdminForm).

Any ideas?

I know I could solve this by showing both forms from a 3rd place, like

LoginForm.ShowModal();

if <check some variable from LoginForm to see if user logged in successfully> then begin
  AdminForm.ShowModal()
end;

But I am looking specifically for a solution that works from within the ok button handler in the LoginForm.

Upvotes: 0

Views: 782

Answers (1)

Rob Kennedy
Rob Kennedy

Reputation: 163287

The right way is indeed to show both forms from a third place. That place already exists, so it should be no big deal to add a little more code there.

Your pseudo-code for checking "some variable from LoginForm" doesn't need to exist; the login form's modal result already tells you whether someone managed to log in:

if LoginForm.ShowModal = mrOK then
  AdminForm.ShowModal;

The login form's task is to handle logging in. The login form should not concern itself with what's supposed to happen after that task is complete. It's the "third place" whose job it is to drive the program and link all the separate parts together.

If you really must make the login form's ShowModal method not return until administration is also complete, then you can simply hide the login form from within the admin form:

procedure TAdminForm.FormShow(Sender: TObject);
begin
  LoginFOrm.Hide;
end;

Upvotes: 1

Related Questions