Solved

What is the best way to terminate an application without getting runtime error messages (at application startup)

Posted on 2004-04-19
5
420 Views
Last Modified: 2010-05-18
Im trying to use a splash/login screen at the beginning of my application.
If they press the cancel button though, i.e. they dont want to login, they started the app by accident, I just want the program to stop

I presumed it was  >Application.Terminate<  but I get error messages.
What lines of code am I missing so that I close the application correctly

Thanks in advance
0
Comment
Question by:mikelittlewood
5 Comments
 
LVL 4

Expert Comment

by:mbprogrammer
ID: 10858747
you can use Application terminate in your splash form and then place the following lines in your project pas file after calling the splash if its a showmodal otherwise place it before Application.Run if it (splash form) isn't  a ShowModal form;

var
  P:Pointer;
begin

  //----- Your code showing splash
       if(Application.Terminated) then
       begin
           P := @Application.Mainform;
           Pointer(P^) := SplashForm;
          //  In C++Builder
          //*(&(Application->MainForm)) = (TForm *)SplashForm;
           Application.Run();
           exit;
      end;
  //----- Your code
end;


or you can use ExitProcess instead of all above . but sometimes it raises an exception which could not be handled by normal try catch .
0
 
LVL 20

Accepted Solution

by:
Madshi earned 50 total points
ID: 10860311
ExitProcess almost always works without any errors.
0
 

Expert Comment

by:ckiraly
ID: 10860347
I've used the following in several programs without problems:

TfrmSplash.btCancel;
begin

end;
0
 

Expert Comment

by:ckiraly
ID: 10860443
Sorry - that submitted before I was finished typing it out...

TfrmSplash.btCancelClick(Sender: TObject);
begin

application.Terminate;
exit;

end;   //cancel button

HOWEVER...

If your splash screen normally loads from other forms, you can do this:

on your loading form (such as Datamod1) set up a global variable:

flgCancel:  Boolean;

then in your formcreate:

procedure TDM1.DataModuleCreate(Sender: TObject);
begin
flgCancel := False;

if SplashScreen = nil then
   Application.CreateForm (TSplashScreen, SplashScreen);

SplashScreen.showmodal();

if flgCancel then
   begin
   application.terminate;
   exit;
   end;

end;   //datamod create

Then, on the splashscreen form have your cancel button:

TSplashScreen.btnCancelClick(Sender: TObject);
begin

flgCancel := True;
close;

end;   //cancel button

That should close your application without errors.  
0
 
LVL 15

Author Comment

by:mikelittlewood
ID: 10863075
Thanks for all help.

The exitprocess worked fine though I have taken note of the others for future reference
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question