[Lazarus] RE : Embedding a standard dialogue

Ludo Brands ludo.brands at free.fr
Wed Apr 18 11:51:25 CEST 2012


> 
> 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.

Ludo





More information about the Lazarus mailing list