Delphi XE2 新服务 - 为什么它包含这些 VCL 单元?
我有点困惑,为什么当你在Delphi XE2中创建一个新的服务应用程序时,它包含这3个视觉组件单元?
Vcl.Controls
Vcl.Dialogs
Vcl.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.Graphics
As 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是由 IDE 代码生成器添加的,“以防万一”...
IDE 主要创建表单,因此即使您的服务中不需要 UI,它也会将其添加到您的服务模块中。
有趣的是,从 Windows Vista/7 开始,服务不再能够向桌面发送 GDI 消息,即与其交互。因此,绝对不可能使用 Windows 服务中的对话框或 UI 控件。
事实上,甚至
SvcMgr.pas
也链接到Forms.pas + Dialogs.pas
单元。因此,删除您自己的单元中的引用将继续链接这些单元。在命令行上安装服务时,
SvcMgr.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 toForms.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 bySvcMgr.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
norDialogs.pas
units.