Board index » delphi » How can I exit during program load?

How can I exit during program load?

I'm having some trouble with an application. The first form is
frmMain, but it immediately loads frmLogin, which makes the user
log in. The user can press Exit to quit the app from the login form.
frmLogin returns the modal result, but if frmMain then calls Halt,

I get an EInvalidOperation exception. frmMain calls frmLogin.ShowModal
in the Activate event. The same error occurs if called from the
OnShow event. If I call frmLogin from the Create event (where
it seems you can safely halt), I get an EAccessViolation,
presumably caused by the BDE stuff that frmLogin uses.

The obvious answer is to restructure things so that frmLogin
is the startup form. However, users may disable the login stuff
and proceed directly to frmMain. I could make frmLogin hide itself
if it wasn't needed, but then we have the can't hide in OnShow/Activate
problem again.

Is there any way to get a normal procedure to be the startup,
rather than a form? You could do this in Visual Basic, as I recall.
In Turbo Vision I once modified the project source (equivalent)
to do some other things before TApplication.Run, but I'm not
sure this is such a good idea. Using a procedure as the startup
code, I could call frmLogin if needed, and then frmMain if needed.

Or any other solutions?

Not being able to hide during Activate/Show is a bit of a disappointment,
since Visual Basic 3.0 had this. Still, at least Delphi 2 doesn't GPF
over it look Delphi 1 liked to.

thanks,

Hamish
--
Hamish Moffatt, moff...@yallara.cs.rmit.edu.au,     Melbourne, Australia.
Student, computer science & computer systems engineering. 2nd year, RMIT.
http://yallara.cs.rmit.edu.au/~moffatt             CPOM: [****      ] 40%

 

Re:How can I exit during program load?


In article <5af7b9$6k...@goanna.cs.rmit.edu.au>,
  moff...@yallara.cs.rmit.edu.au (Hamish Moffatt) wrote:

Quote

> I'm having some trouble with an application. The first form is
> frmMain, but it immediately loads frmLogin, which makes the user
> log in. The user can press Exit to quit the app from the login form.
> frmLogin returns the modal result, but if frmMain then calls Halt,

      Don't use Halt.

Quote
> I get an EInvalidOperation exception. frmMain calls frmLogin.ShowModal
> in the Activate event. The same error occurs if called from the
> OnShow event. If I call frmLogin from the Create event (where
> it seems you can safely halt), I get an EAccessViolation,
> presumably caused by the BDE stuff that frmLogin uses.

> The obvious answer is to restructure things so that frmLogin
> is the startup form. However, users may disable the login stuff
> and proceed directly to frmMain. I could make frmLogin hide itself
> if it wasn't needed, but then we have the can't hide in OnShow/Activate
> problem again.

> Is there any way to get a normal procedure to be the startup,
> rather than a form? You could do this in Visual Basic, as I recall.
> In Turbo Vision I once modified the project source (equivalent)
> to do some other things before TApplication.Run, but I'm not
> sure this is such a good idea. Using a procedure as the startup
> code, I could call frmLogin if needed, and then frmMain if needed.

      You should be able to simply edit the dpr file (View Program
Source). Psuedo-code: right now in the dpr you see

Application.ThisAndThat;

You could replace this with

LoginForm:= TLoginForm.Create;
LoginForm.ShowModal;
if LoginForm.ModalResult:= mrOK then
begin
    Application.ThisAndThat;
end;

David Ullrich
-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet

Other Threads