当你在Delphi XE2中创建一个新的服务应用程序时,为什么它包含这3个可视组件单元,我有点疑惑?
Vcl.Controls Vcl.Dialogs Vcl.Graphics据我所知,这些单位没有任何服务需要的东西。 我可以看到Graphics单元可能用于某种图像处理,但这是开发人员实现它的问题。 为什么这些单位被自动包含在新的服务应用程序中有什么原因? 如果我删除它们,它不会伤害任何东西......或者是吗?
I'm a little puzzled as to why, when you create a new service application in Delphi XE2, does it include these 3 visual component units?
Vcl.Controls Vcl.Dialogs Vcl.GraphicsAs far as I know, there's nothing in these units which a Service would require. I can see the Graphics unit possibly being used for some sort of image processing, but that's a matter of a developer's implementation of it. Is there some reason why these units are automatically included in a new service application? If I remove them, it doesn't hurt anything... Or does it?
最满意答案
这是由IDE代码生成器添加的,“以防万一”... IDE主要创建表单,因此即使您的服务中不需要UI,它也会将其添加到您的服务模块中。
有趣的是,自Windows Vista / Seven以来,服务不再能够将GDI消息发送到桌面,即与之交互。 因此,从Windows服务中使用对话框或UI控件是绝对没有可能的。
事实上,即使是SvcMgr.pas链接到Forms.pas + Dialogs.pas单位。 因此,删除自己单位中的参考文献将继续保持这些单位的联系。
Forms.pas + Dialogs.pas似乎需要Forms.pas + Dialogs.pas单位才能在命令行上安装服务时显示一些潜在的错误消息。
实际上,您的服务.exe不仅仅是作为服务在后台运行。 它也可以从命令行运行,就像常规应用程序一样,以便安装/卸载/启动/停止服务。
您可以在Delphi中查看我们较轻的Windows服务实现 - 但不是相同的功能 - 只是使用API进行操作。 此版本不链接到Forms.pas或Dialogs.pas单元。
This is added by the IDE code generator, "just in case"... IDE mainly creates forms, so it will add it to your service module, even if there is no need of UI in your service.
What is funny, is that since Windows Vista/Seven, the services are not able any more to send GDI messages to the desktop, i.e. interact with it. So there is definitively not even a possibility to use dialogs nor UI controls from a Windows service.
In fact, even the SvcMgr.pas links to Forms.pas + Dialogs.pas units. So deleting the reference in your own unit will continue to have those units linked.
It appears that Forms.pas + Dialogs.pas units are needed by SvcMgr.pas to display some potential error message when the service is installed on the command line.
In fact, your service .exe is not just running in the background, as a service. It can also be run from the command line, like a regular application, in order to install/uninstall/start/stop the service.
You can take a look at our lighter implementation of Windows services in Delphi - but not the same features - just something to play with the APIs. This version does not link to Forms.pas nor Dialogs.pas units.
更多推荐
发布评论