Alternative to Application.DelayInitialize for Delphi 7 Service?

471 views Asked by At

Is there an alternative to Application.DelayInitialize for Delphi 7? I'm trying to create a Delphi 7 Service that hosts a COM Server but it doesn't work and I believe it is because I'm not using Application.DelayInitialize.

Re: Windows Service / DelayInitialize

1

There are 1 answers

0
Remy Lebeau On BEST ANSWER

I have written several COM-hosting services using BCB6, and they all work fine in all Windows versions from Win9x onwards, so I have had to deal with this same issue many times.

Simply don't call Application.Initialize() at process startup on Win2003+, wait until the TService's OnStart or OnExecute event to call it. That way, the service API is running before any COM objects are initialized.

The trick is to delay the call to Application.Initialize() ONLY on Win2003+ and ONLY when the service is actually running. DO NOT delay the call if either:

  1. The service is running on Windows versions earlier than 2003.
  2. when the service is being (un)installed.
  3. when the COM object is being (un)registered.

Under those conditions, call Application.Initialize() normally at process startup.

So, you will need to check the OS version and the command line parameters to know when to call Application.Initialize() correctly.