Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-04

Embedding a standard dialogue

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd

Is it possible to embed a standard dialogue in a custom form? For example, if I wanted to filter text input through a user-specified regular expression, can I set up a form containing a file-open dialog plus an edit box for the regex, or do I have to implement it from scratch?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Juha Manninen
to Mark Morgan Lloyd

On Tue, Apr 17, 2012 at 12:17 PM, Mark Morgan Lloyd <

Show quoted text 7 lines
wrote: Is it possible to embed a standard dialogue in a custom form? For example, if I wanted to filter text input through a user-specified regular expression, can I set up a form containing a file-open dialog plus an edit box for the regex, or do I have to implement it from scratch?

No, you must create your own dialog from scratch.

Juha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120417/ab48b8ae/attachment-0001.html>

Reply by email

Mark Morgan Lloyd
to Mark Morgan Lloyd: Is it possible to embed a standard dialogue in a custom form? For example, if I wanted to…

Apologies for my lousy threading here, a message got chopped by our firewall.

Show quoted text 9 lines
> Is it possible to embed a standard dialogue in a custom form? For > example, if I wanted to filter text input through a user-specified > regular expression, can I set up a form containing a file-open > dialog plus an edit box for the regex, or do I have to implement > it from scratch? No, you must create your own dialog from scratch. Juha

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?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Antonio Fortuny
to Mark Morgan Lloyd

Le 18/04/2012 09:42, Mark Morgan Lloyd a ?crit :

Show quoted text 20 lines
Apologies for my lousy threading here, a message got chopped by our firewall. > > Is it possible to embed a standard dialogue in a custom form? For > > example, if I wanted to filter text input through a user-specified > > regular expression, can I set up a form containing a file-open > > dialog plus an edit box for the regex, or do I have to implement > > it from scratch? > > No, you must create your own dialog from scratch. > > Juha 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.

For such cases I build a DataModule whith auto creation. In the DataModule OnCreate event code I create and display a modal little window asking for credentials. Depending on user's answers I cancel the program. Make sure the login form is NOT auto crated. If credentials are OK, processing continues as usual and the main form is created and displayed.
The only thing to take care of is to make sure that the creation of the DataModule is done BEFORE the main form in the project code (.dpr or .lpr) Because the DataModule is never displayed, that's it.

Antonio.

Show quoted text 7 lines
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?

Reply by email

Unknown author
to Mark Morgan Lloyd: Apologies for my lousy threading here, a message got chopped by our firewall. OK, If I…

Sorry, on cell, so formatting limited here too.

Sample login form for mssql and sybase, i.e. 2 dbs at bug 21619... committed as sample program in trunk. I think the sample form could easily extended to support more dbs... Actually want to do that some day and get it into lazarus...

Ludo brands came up with the original code at the forum... Sorry, cannot find link here.

Regards,
Reinier
On 18-04-12 09:42 Mark Morgan Lloyd wrote:
Apologies for my lousy threading here, a message got chopped by our firewall.

Show quoted text 9 lines
> Is it possible to embed a standard dialogue in a custom form? For > example, if I wanted to filter text input through a user-specified > regular expression, can I set up a form containing a file-open > dialog plus an edit box for the regex, or do I have to implement > it from scratch? No, you must create your own dialog from scratch. Juha

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?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] --

Reply by email

Mark Morgan Lloyd
to Antonio Fortuny: Le 18/04/2012 09:42, Mark Morgan Lloyd a ?crit : For such cases I build a DataModule…
Antonio Fortuny wrote 37 lines
Le 18/04/2012 09:42, Mark Morgan Lloyd a ?crit : > Apologies for my lousy threading here, a message got chopped by our > firewall. > > > > Is it possible to embed a standard dialogue in a custom form? For > > > example, if I wanted to filter text input through a user-specified > > > regular expression, can I set up a form containing a file-open > > > dialog plus an edit box for the regex, or do I have to implement > > > it from scratch? > > > > No, you must create your own dialog from scratch. > > > > Juha > > 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? > For such cases I build a DataModule whith auto creation. In the DataModule OnCreate event code I create and display a modal little window asking for credentials. Depending on user's answers I cancel the program. Make sure the login form is NOT auto crated. If credentials are OK, processing continues as usual and the main form is created and displayed. The only thing to take care of is to make sure that the creation of the DataModule is done BEFORE the main form in the project code (.dpr or .lpr) Because the DataModule is never displayed, that's it.

Thanks, will follow up.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Mark Morgan Lloyd
to Unknown author: Sorry, on cell, so formatting limited here too. Sample login form for mssql and sybase,…
Show quoted text 37 lines
Sorry, on cell, so formatting limited here too. Sample login form for mssql and sybase, i.e. 2 dbs at bug 21619... committed as sample program in trunk. I think the sample form could easily extended to support more dbs... Actually want to do that some day and get it into lazarus... Ludo brands came up with the original code at the forum... Sorry, cannot find link here. Regards, Reinier On 18-04-12 09:42 Mark Morgan Lloyd wrote: Apologies for my lousy threading here, a message got chopped by our firewall. > > Is it possible to embed a standard dialogue in a custom form? For > > example, if I wanted to filter text input through a user-specified > > regular expression, can I set up a form containing a file-open > > dialog plus an edit box for the regex, or do I have to implement > > it from scratch? > > No, you must create your own dialog from scratch. > > Juha 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?

Thanks, I'll investigate. I notice that the form I set up allowed the server type, name/address, port, SSL usage, user name and password to be set up.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Ludo Brands
to Mark Morgan Lloyd: Apologies for my lousy threading here, a message got chopped by our firewall. OK, If I…
Show quoted text 18 lines
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

Reply by email

Mark Morgan Lloyd
to Ludo Brands
Ludo Brands wrote 45 lines
> 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]

Reply by email