Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi XE2 New Service - Why does it include these VCL units?

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?

like image 972
Jerry Dodge Avatar asked Feb 21 '23 12:02

Jerry Dodge


1 Answers

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.

like image 191
Arnaud Bouchez Avatar answered Mar 10 '23 09:03

Arnaud Bouchez