Re:How do I close close my connection to word and still leave the document open.
<<DJ McNeill:
So if I want to repeatly open a document template into a
word document I will have to dynamically create a
TWordApplication each time?
No, certainly not!
All these components have Connect and Disconnect methods.
These have nothing to do with creating and freeing the
components, but they control the components' connection to
active instances of Word and Word documents. The error you
described in your first post comes from having a Word
application component that thinks it is connected to a Word
application instance, when the latter has actually been
closed. (It doesn't matter if another one has been started
later, the component still refers to the closed one.) When
it tries to access this no-longer-existent application,
there is naturally an error. To stop this from happening
you have to call the Disconnect method of a component
whenever the object it is connected to is closed.
<<DJ McNeill:
So what is the correct method of allowing this function to
run multiple times.
At the beginning of the function, where you open the
document, use the TWordDocument's ConnectTo method to
connect it to the document. At the end of the function,
call the TWordDocument's Disconnect method. If Word itself
will be closed at any point, call the TWordDocument's and
TWordApplication's Disconnect methods.
--
Deborah Pate (TeamB) http://delphi-jedi.org
Use Borland servers; TeamB don't see posts via ISPs
http://www.borland.com/newsgroups/genl_faqs.html