Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A standalone Delphi application that can also be installed as windows service

In Delphi you can create a standalone Windows VCL Forms application. You can also create a Windows service application.

Is it possible to combine the two in a single application that can run as a standalone application and can also be installed as a Windows service?

like image 272
Vic Avatar asked Mar 05 '10 14:03

Vic


1 Answers

Totally possible. The trick is to edit the .dpr to create main form when you want to run as an application and the service form when you want to run as a service. Like this:

if SvComFindCommand('config') then begin   //When run with the /config switch, display the configuration dialog.   Forms.Application.Initialize;   Forms.Application.CreateForm(TfrmConfig, frmConfig);   Forms.Application.Run; end else begin   SvCom_NTService.Application.Initialize;   SvCom_NTService.Application.CreateForm(TscmServiceSvc, scmServiceSvc);   SvCom_NTService.Application.Run; end; 

The code above uses SvCom to run the service but exactly the same effect could be achieved using the standard TService.

I wrote an article about that for The Delphi Magazine many years ago. You can read it here: Many Faces Of An Application.

like image 78
gabr Avatar answered Oct 04 '22 11:10

gabr