你如何干净地中止Delphi程序?

时间:2009-07-26 16:09:31

标签: delphi shutdown abort

我有一个程序在关机期间遇到了一些问题,引发了我无法追溯到其来源的异常。它似乎与时间相关且不确定。这是在所有共享资源被释放后发生的,并且由于它已经关闭,内存泄漏不是问题,所以这让我想知道是否有任何方法只是告诉程序在释放共享资源后立即和静默终止,而不是继续关闭序列并给出一个异常消息框。

有谁知道怎么做?

5 个答案:

答案 0 :(得分:19)

查看Delphi Run Time Library源代码和Microsoft文档后;我可以证实Mason和Paul-Jan的评论。

关闭的层次结构如下

  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

答案 1 :(得分:6)

ExitProcess(0)?

答案 2 :(得分:4)

Halt(0)曾经是一种老式的方式,告诉程序立即生效。现在可能有更多Delphi友好的方式,但我95%肯定停止(0)仍然有效。 :-)

答案 3 :(得分:4)

如果HeartWare建议使用ExitProcess()失败,可能是您使用的DLL不能很好地响应DLL_PROCESS_DETACH。在这种情况下,请尝试使用TerminateProcess(getCurrentProcess,0);

一旦你采取了这样的措施,人们可能会怀疑主题标题的“干净”部分是否仍然需要仔细审查。

答案 4 :(得分:1)

我最后一次遇到这样的问题是关机导致了一个事件(调整大小?已经有一段时间了。)在垂死的窗口上开火,导致尝试重新绘制需要已经存在的东西的东西被处置掉了。