how to terminate a Delphi application?

How do I immediatly terminate a Delphi application in formCreate?
application.terminate does not immediatly termiantes an application.
jorge_cAsked:
Who is Participating?
 
MadshiCommented:
It's much easier! Simply call "ExitProcess(0)". This works always perfectly, regardless where you put it in your code...

Regards, Madshi.
0
 
edeyCommented:
in an event driven system, nothing happens "immediatly", do you want to give the impression it does?

GL
Mike
0
 
bcolemanCommented:
try 'halt'
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
DippenCommented:
Use a global boolean variable, for instance called RunApplication, and declare it publically in the main unit.
Then, in the formCreate, you set the variable to False if the application shouldn't be launched at all. Finally, somewhere in the project source (.dpr file), add the lines:

if not RunApplication then begin
  application.terminate;
  exit;
end;

The lines should be added somewhere after the Application.CreateForm statements and (important) before
the Application.Run statement!

Another solution is to move the code that does the checking from the formCreate method to the project source...

Hope this helps!

Regards, Daniel
0
 
MadshiCommented:
P.S: Halt works in some cases and in some not, I don't remember where it didn't work. Anyway, it doesn't matter, ExitProcess works always.
0
 
jorge_cAuthor Commented:
Thanks for all you answers. calling ExitProcess(0) works great for me.
Now, how do I give the points to Madshi?
0
 
MadshiCommented:
First reject Dippen's answer. Then you can accept my comment as the answer.

Thank you...   :-)
0
 
jorge_cAuthor Commented:
calling ExitProcess(0) works better for me since I have to call it from different places in my code.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.