Board index » delphi » How to exit Delphi app with return code?

How to exit Delphi app with return code?

What is the best way to exit a Delphi program and set a return code that
can be tested by the program which launched it?  Halt(retcode) does
this, but I am not sure if Halt terminates the app cleanly.  Does anyone
know?
--
Julian Moss                                      J M Technical Services
{*word*19}ermouth, Cumbria, UK                 Technical Writing and Software
(+44) 1900 826514                              jm...@jmtech.demon.co.uk
 

Re:How to exit Delphi app with return code?


Quote
Julian Moss <jm...@jmtech.demon.co.uk> wrote:
>What is the best way to exit a Delphi program and set a return code that
>can be tested by the program which launched it?  Halt(retcode) does
>this, but I am not sure if Halt terminates the app cleanly.  Does anyone
>know?
>--
>Julian Moss                                      J M Technical Services
>cockermouth, Cumbria, UK                 Technical Writing and Software
>(+44) 1900 826514                              jm...@jmtech.demon.co.uk

I don't know, but it looks like whatever causes the exit,
the error code will be stored in System.ExitCode, and I
think you could define an exit procedure to have the last
word on its value before it is finally passed to windows.

E.g., if you had a global MyExitCode that you set somewhere,
then you could use Application.Terminate, or Halt, or
RunError, or anything you like to exit, yet always do
System.ExitCode := MyExitCode; in your exit proc (or
maybe better only to substitute your own when the normally
generated code says success (zero) zero up to that point,
and use a non-overlapping range of codes for yours).

I wonder how different things would have been if terminating
DOS programs had passed a PChar to a temp (system owned) result
buffer on exit instead of an errorlevel byte? I better not get
started...

HTH, speculative as it is.
Regards,
Bengt Richter

Re:How to exit Delphi app with return code?


Don't use the HALT and RUNERROR procedures as they will let the program
fall out without freeing any variables or the environment and keep all
files and ports open

Other Threads