[69305 Closed] How to implement service event handlers

Using a combo server, how can I add event handlers for the TService object from which TROService derives?

I need to add handlers to the AfterInstall, AfterUninstall and other event handlers so I can log when the service is installed, uninstalled, started, stopped and so forth. In my own service applications this is no problem but I can’t see how I can add handlers to the TROService object.

for caught such events, you need to create own ROStartService method because service is installed and uninstalled in this method.
I can suggest to create own descendant from TROService, which will contain logging and use it in your replica of ROStartService.

Ok thanks. It seems it’s easy enough to add handlers for OnStart and OnStop after ROStartService has been called but, as you say, I can’t intercept the installation and uninstallation events unless I replace ROStartService.

Had a look at this but it seems I can’t easily replace ROStartService in my own unit due to the variables involved being in the implementation section of uROComboService and thus inaccessible by other units. Seems the only way would be to directly modify uROComboService which I don’t really want to do as it causes hassle when upgrading RO.

Could I make a suggestion that you implement some type of class factory & metaclass system which facilitates easy sub-classing of TROService? At present I can’t find any way of intercepting the installation and uninstallation of the service, which I want to do both for logging purposes and to configure registry settings for the event log message file.

Thanks, logged as bugs://69305: allow to use custom class of TROService in ROStartService

bugs://69305 got closed as fixed

update uROComboService .pas as

type  TROServiceClass = class of TROService;
var   DefaultROServiceType: TROServiceClass;
implementation
..
function ROStartService(const aServiceName, aDisplayName: string; aDescription: string = '';
..
begin
  if DefaultROServiceType = nil then DefaultROServiceType := TROService;  //added
..
  ROService := DefaultROServiceType.CreateNew(SvcMgr_Application, 0); //changed
..
  ROService := DefaultROServiceType.CreateNew(SvcMgr_Application, 0); //changed
..

Ah excellent - I take it this will be in the next release so, if I make the changes to my installation, they’ll still be there when I next upgrade?

yes, changes were made in main trunk