Ludo Brands wrote:
OK, If I can lead on from this. The cause of bug 21792 that I raised yesterday is, I'm told, that I'd set the main form visible but minimised. The reason I'd done this is that before the form was displayed I wanted the user to provide database login credentials, I couldn't rely on a standard dialogue for that since I also needed to have him select what kind of database- PostgreSQL or Firefox- as well as the server and possibly port.

What is the correct thing to do in this sort of situation? I've seen a description of a hack for Delphi which relied on creating the main form manually, should something like that be attempted for Lazarus?

Or should I simply redo the app so that the login is the main form?


In the OnCreate handler for the main form, you can create your login form
and do a showmodal of that form. In Oncreate the main form isn't visible
yet. In case the user can't provide correct credentials, call
application.terminate: under gtk2 the main form will never show, windows
shows the main form in a very short flash which can be avoided by setting
windowstate:=wsminimized; just before application.terminate.

procedure TFormMain.FormCreate(Sender: TObject);
begin
  FormLogin:=TFormLogin.create(self);
  while true do
    case FormLogin.showmodal of
      mrAbort:
        begin
        windowstate:=wsminimized;
        application.terminate;
        break;
        end;
      mrOK:
        break;
end; FormLogin.destroy;
end;

This will loop on the login form until the user aborts (mrAbort) or the
correct login credentials are provided (mrOK). You can do the credential
check in the login form or in the mrOK case if you like.

Thanks Ludo, "clear as a bell" :-)

I'm already tinkering in various apps with getting things to happen at various times relative to the validity of the main form object, it just hadn't occurred to me that I could forcibly create a premature login form.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to