After making a few various services in Delphi, I’ve realized that the TService is lacking some of the necessary things which should come with a service application, such as logging, exception handling, and the ‘Description’ property in the registry.
I was wondering if it’s possible for me to make my own service shell such as TJDService which is inherited from a TService but with some additional things, such as a ‘Description’ property showing in the object inspector. Can I make my own service shell like this? I know I can make my own “default project” inheriting from a TService but that includes all my code with any new project.
When a new service is created, it should look like this:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes, Vcl.SvcMgr,
JDServices;
type
TJDService1 = class(TJDService)
private
public
function GetServiceController: TServiceController; override;
end;
var
JDService1: TJDService1;
implementation
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
JDService1.Controller(CtrlCode);
end;
function TJDService1.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
end.
Same as a typical service, but using my TJDService instead of just TService.
Simple question with a simple answer. Yes you can do this. I do exactly this myself to share code between the various services that are implemented in my company’s codebase.
RegisterCustomModuleis the way to make yourDescriptionproperty show up in the Object Inspector. Having said that, I don’t find the ability to set these service properties in the Object Inspector to be all that valuable. I would regard it perfectly acceptable to set them at runtime in code, but that decision is down to personal preference.Even if you use
RegisterCustomModuleto make your service class known to the IDE, the default new service application will not use your service class. You can customise the default service application to your needs and then save it to the Object Repository.My answer here shows how I implement an app that can be run as either a service or as a standard desktop process for debugging purposes.