Don't mess with the auto-create order. The very first form auto-created is the application's main form, which you probably don't want to be the login dialog.
You can do one of three things.
a6m1n0's suggestion is to edit your
dpr file directly (go to Project --> View Source) and create and use the form directly:
Code:
program foo;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
...,
uLoginDialog in 'uLoginDialog.pas' {LoginDialogForm};
{$R *.res}
begin
{begin new stuff}
with TLoginDialogForm.create( nil ) do try
try
if ShowModal <> mrOK then Exit
finally free end
except Exit end;
{end new stuff}
Application.Initialize;
Application.CreateForm( TForm1, Form1 );
...
Application.Run;
end.
The
TLoginDialogForm is your login dialog. In this example it is created as a parent-less top-level form. It should not appear in the auto-create project options. It should ask the user to login and attempt to verify his response (allowing the user to try one or more times, typically three). If successful, it sets
ModalResult to
mrOK. If not successful, it sets it to something else (like
mrAbort or whatever).
If the dialog fails for any reason the program is aborted without doing anything else.
If you don't want to mess with your
dpr file directly, you'll have to use one of the following variations:
Variation One (Recommended)
In your
uLoginDialog unit (or whatever you named it), add the following down at the bottom:
Code:
var LastInitProc: pointer;
procedure Login; // You can name this procedure anything you like
begin
with TLoginDialogForm.create( nil ) do try
try
if ShowModal <> mrOK then Application.Terminate
finally free end
except Application.Terminate end;
if not Application.Terminated and Assigned( LastInitProc )
then TProcedure( LastInitProc )
end;
initialization
LastInitProc := InitProc;
InitProc := @Login
end.
This method does the very same thing as the first, but it keeps stuff out of the
dpr. That is the first reason why I like it: it allows you to keep related things in their own unit instead of 'contaminating' other units.
The second is that it is transparent, meaning that you don't have to worry about modifying the call to your initialization procedure ('Login' in this example) anywhere --you know that Application.Initialize will call it properly after all units are loaded but before any forms are created. Adding or removing such specialized initialization code is just a matter of including or excluding the relevant unit.
Variation Two
Put the login code in your main form's constructor.
Code:
procedure TForm1.FormCreate( Sender: TObject );
begin
with TLoginDialogForm.create( nil ) do try
try
if ShowModal <> mrOK then Application.Terminate
finally free end
except Application.Terminate end;
if Application.Terminated then Exit;
{normal constructor stuff goes here}
end;
This works as well, but again it is entangled into a separate module's code. Also, you might see the main form flash on screen before the application terminates.
Hope this helps.