Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you cleanly abort a Delphi program?

I've got a program that's having some trouble during shutdown, raising exceptions that I can't trace back to their source. It appears to be timing-related and non-deterministic. This is occurring after all shared resources have been released, and since it's shutdown, memory leaks are not an issue, so that makes me wonder if there's any way to just tell the program to terminate immediately and silently after releasing the shared resources, instead of continuing with the shutdown sequence and giving an exception message box.

Does anyone know how to do that?

like image 263
Mason Wheeler Avatar asked Jul 26 '09 16:07

Mason Wheeler


3 Answers

After looking at the Delphi Run Time Library source code, and at the Microsoft documentation; I can corroborate Mason and Paul-Jan comments.

The hierarchy of shutdown is as follows

  Application.Terminate()
    performs some unidentified housekeeping of application
    calls Halt()

  Halt()
    calls ExitProc if set
    alerts the user in case of runtime error
    get rid of PackageLoad call contexts that might be pending
    finalize all units
    clear all exception handlers
    call ExitprocessProc if set
    and finally, call ExitProcess() from 'kernel32.dll'

  ExitProcess() 
    unloads all DLLs
    uses TerminateProcess() to kill the process
like image 86
PA. Avatar answered Oct 31 '22 06:10

PA.


ExitProcess(0) ?

like image 35
HeartWare Avatar answered Oct 31 '22 07:10

HeartWare


Halt(0) used to be the good old fashioned way of telling the program to end with immediate effect. There's probably a more Delphi-friendly way of doing that now, but I'm 95% sure halt(0) still works. :-)

like image 4
robsoft Avatar answered Oct 31 '22 06:10

robsoft