终止delphi应用程序的正确方法是什么? [英] Which is the proper way to terminate a delphi application?

查看:325
本文介绍了终止delphi应用程序的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想终止Delphi应用程序,而不执行任何其他代码行,我想知道哪个是正确的方法。此外,我想知道目前我在做什么有什么问题。
基本上,我的代码看起来像这样:

  //释放所有对象(Obj1.Free等) 
Application.Terminate;
暂停;

这是停止Delphi应用程序的正确方法还是应该以其他方式完成?

解决方案

Application.Terminate()打破 TApplication.Run() TForm.ShowModal(),允许主线程正常退出,执行必要的清理等。



Vcl.Forms.TApplication 。


结束执行应用程序。



调用终止以编程方式结束应用程序。通过调用终止而不是释放应用程序对象,您可以允许应用程序以有序的方式关闭



终止调用Windows API PostQuitMessage 函数来执行应用程序的有序关闭。 终止不立即。
终止在WM_QUIT消息中自动调用当主窗体关闭时。


Halt()手,是立即异常终止。基本上,把内存翻过来。仅在没有其他选项可用的极端情况下使用。



System.Halt


启动程序的异常终止 p>

停止执行程序的异常终止并返回到操作系统。



执行正常终止Delphi应用程序,在全局应用程序对象上调用终止方法。如果应用程序不使用提供应用程序对象的单位,请从主程序块调用 Exit 程序。



I would like to terminate a Delphi application without executing any other code line and I'm wondering about which is the proper way to do this. Furthermore, I would like to know if there's something wrong in what I'm actually doing at the moment. Basically, my code looks like this:

//Freeing all objects (Obj1.Free, etc..)
Application.Terminate;
Halt;

Is this the right way to stop a Delphi application or should it be done in another way?

解决方案

Application.Terminate() breaks the message loops in TApplication.Run() and TForm.ShowModal(), allowing the main thread to exit normally, perform necessary cleanups, etc.

Vcl.Forms.TApplication.Terminate

Ends application execution.

Call Terminate to end the application programmatically. By calling Terminate rather than freeing the application object, you allow the application to shut down in an orderly fashion.

Terminate calls the Windows API PostQuitMessage function to perform an orderly shutdown of the application. Terminate is not immediate. Terminate is called automatically on a WM_QUIT message and when the main form closes.

Halt(), on the other hand, is an immediate abnormal termination. Basically, ripping the process out of memory. Use it only in extreme situations where no other option is available.

System.Halt

Initiates the abnormal termination of a program.

Halt performs an abnormal termination of a program and returns to the operating system.

To perform a normal termination of a Delphi application, call the Terminate method on the global Application object. If the application does not use a unit that provides an Application object, call the Exit procedure from the main Program block.

这篇关于终止delphi应用程序的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆