Solved

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

Posted on 2004-04-19
5
417 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
Comment Utility
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
Comment Utility
ExitProcess almost always works without any errors.
0
 

Expert Comment

by:ckiraly
Comment Utility
I've used the following in several programs without problems:

TfrmSplash.btCancel;
begin

end;
0
 

Expert Comment

by:ckiraly
Comment Utility
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
Comment Utility
Thanks for all help.

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now