Solved

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

Posted on 2004-04-19
5
421 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi parse string to params 3 157
Controlled Assessment GCSE - desperate help needed 4 112
DBGrid or StringGrid ? 6 120
Firemonkey how to swip panel with finger tap 1 23
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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