4
votes

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?

1
Not everything in those is visual....Tony Hopkinson
@TonyHopkinson Understood, but I still don't see, for example, any reason to ever have to show a dialog, because services are invisible, and should never show any dialog. And there's nothing to draw, so why is graphics included?Jerry Dodge
I have no idea, but there's only one way to find out, comment them!user497849
Already have, as mentioned, I can remove them and nothing breaks. I'm just really puzzled as to why they would be included in the first place.Jerry Dodge
Delete them. You don't need or want them.David Heffernan

1 Answers

8
votes

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.