1
votes

With the code bellow, when I call MessageDlg, the modal form disappears.
How to avoid?

...     
LoginForm_Create; //FfrmLoginForm created here
try
  if FfrmLoginForm.ShowModal = mrOk then 
  begin
    Fuser := db_authuser( FfrmLoginForm.edtUserName.Text, FfrmLoginForm.edtPassword.text ); 
  if Fuser <> nil then 
    result := 1
  else begin
    MessageDlg('Username or password invalid', mtError, [mbOK], 0);
    result := -2;
  end;
end else //mrCancel
  result := -1;
finally
  LoginForm_Close; // << FfrmLoginForm.Release;
end;
...
1
That is because the rest of your code is executed after ShowModal. What you should do is put that authentication code e.g. in your FfrmLoginForm.OnShow() handler. You can then set ModalResult to signal success or failure. - Jan Doggen

1 Answers

3
votes

The form is closed when ShowModal returns. Hence the behaviour that you observe.

If you wish your dialog to show on top of the modal form, you need to show it before ShowModal returns. Do that by moving the mrOK code into whichever code on your modal form sets ModalResult to mrOK.