Board index » delphi » Keeping OLE server running after client terminated

Keeping OLE server running after client terminated

I'm working on a project using OLE automation to control MS Word 95.
In some situations i want my program to start Word, do something to
the Word document, then terminate and keep Word running.
But when Word doesn't have any more clients to service it shuts down
automatically.

Does anyone know how to prevent this?

Peter Allin.

 

Re:Keeping OLE server running after client terminated


You can manually increase the referencecount (Also known as 'Locking') by
calling  _addref.
Like:
var
 Word:_Application;

begin
Word:=coApplication.create;
//This prevents word from being released
  Word._addreff
end.

Re:Keeping OLE server running after client terminated


Quote
Thaddy de Koning wrote:
> You can manually increase the referencecount (Also known as 'Locking')
> by
> calling  _addref.
> Like:
> var
>  Word:_Application;

> begin
> Word:=coApplication.create;
> //This prevents word from being released
>   Word._addreff
> end.

Not sure, but it seems that inrementing the counter will fool Word into
believing that there is still an OLE Controller attached even after the
OLE Controller terminated.  If you try to exit Word, doesn't it say that
there are OLE connections that will be lost?

Why not just tell Word to start and then do the OLE Automation.  This
way, Word will increment its Reference Count prior to the OLE connection
incrementing it.  When the OLE connection terminates and the Reference
Count is decremented, it will still be greater than 0 and won't
terminate until the user manually exits (or you tell it to close).

This sort of steps around some of the benifits of OLE Automation and
auto startup/shutdown, but it seems that you are trying to do this
anyway.

Other Threads