Solved

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

Posted on 2004-04-19
5
419 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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 …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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