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.
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:
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.