We help IT Professionals succeed at work.

second use of TWordApplication

danGynn
danGynn asked
on
Medium Priority
1,355 Views
Last Modified: 2008-10-28
If I use a TWordApplication to fill in some values and then display the document to the user.  When the user closes Word, and then tries to run the report again, I get an error saying "The UPC Server is unavailable".  I can not use the TWordApplication.  What does this mean and how do I work around it.
Comment
Watch Question

Commented:
I had the same prob. AFAIK the only solution is to change:

wordApplication1.connect;

to:

wordApplication1.disconnect;
wordApplication1.connect;

GL
Mike
Russell LibbySoftware Engineer, Advisory
CERTIFIED EXPERT
Top Expert 2005

Commented:

According to the MSDN, you should be issuing a Quit() to the Word.Application OLE server before releasing your COM interface to it. Otherwise, the OLE server (Word in this case) will remain running, and fail a new call to connect.

I am not sure if you are using someone elses COM wrapper, or Delphi 5's, but the prinicple is still the same.

In Delphi 5, the ConnectKind should be set to ckRunningOrNew. This forces delphi to check the running object table for Word. If not found, then it will create a new instance.
If your own wrapper, use GetActiveObject to see if Word is in the running object table, if not then create a new instance.

Russell

Author

Commented:
Yep, that is all that needed done

Commented:
Glad to be of service :)

GL
Mike

Explore More ContentExplore courses, solutions, and other research materials related to this topic.