Board index » delphi » Shutting down a program during startup

Shutting down a program during startup

I perform error checking in the OnCreate methods of some forms and want to
allow the user to shutdown the application if certain errors occur, e.g.
DLLs aren't available.  I've tried calling the Halt method but seem to get
unexplainable general protection faults.  I suspect its because I'm calling
'Halt' before all forms have been auto-created and the Application.Run line
has executed in the project file.  Does anybody know of a neat way (in
Delphi 1, 2 or 3)  of shutting down a program before it has been completely
initialised.

--
Andrew Jackson
ajack...@cccgroup.co.uk

 

Re:Shutting down a program during startup


Quote
Andrew Jackson wrote:

> I perform error checking in the OnCreate methods of some forms and want to
> allow the user to shutdown the application if certain errors occur, e.g.
> DLLs aren't available.  I've tried calling the Halt method but seem to get
> unexplainable general protection faults.  I suspect its because I'm calling
> 'Halt' before all forms have been auto-created and the Application.Run line
> has executed in the project file.  Does anybody know of a neat way (in
> Delphi 1, 2 or 3)  of shutting down a program before it has been completely
> initialised.

        First, you should stop using Halt - it doesn't clean things up the
way you'd want.

        Probably the best place to decided whether to run your program
is in the dpr - change the current dpr to

if Whatever then
begin
  Application.This;
  Application.That;
end
else
begin
  DisplayErrorMessage;
end;

If Whatever = False the program will simply exit before creating any forms.

--
David Ullrich

?his ?s ?avid ?llrich's ?ig ?ile
(Someone undeleted it for me...)

Re:Shutting down a program during startup


: "Andrew Jackson" <ajack...@cccgroup.co.uk> wrote:

Quote
>I perform error checking in the OnCreate methods of some forms and want to
>allow the user to shutdown the application if certain errors occur, e.g.
>DLLs aren't available.  I've tried calling the Halt method but seem to get
>unexplainable general protection faults.  I suspect its because I'm calling
>'Halt' before all forms have been auto-created and the Application.Run line
>has executed in the project file.  Does anybody know of a neat way (in
>Delphi 1, 2 or 3)  of shutting down a program before it has been completely
>initialised.

Instead of using OnCreate you should override create and simply
raise an exception...

TMyForm.Create(aowner: tcomponent); {override}
begin
  inherited Create();

  if not condition then
    raise MyException.Create('Condition not met!');
end;

If this happens in a auto-created form (something you should give
up using for resource / speed reasons) the exception will get
through to the DPR level and terminate the program...

If you are manually creating forms, simply Application.Terminate
(?) the thing.
--
Stefan.Hoffmeis...@Uni-Passau.de
http://kakadu.rz.uni-passau.de/~w4hoff01/

Other Threads