Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to know when an Ole Object can be Destroyed - Word Doc

Status
Not open for further replies.

Statey603

Programmer
Nov 10, 2009
196
US
PB 12.6
I have an OLE Object being used to open a Word Document for the user to view. The issue that I have is that I do not know when or if the user closes the session of Word that gets launched so am not sure how to handle Destroying the object.

I appreciate any comments, examples, recommendations on how to handle this situation.
Thanks,
Bill

----------------------------
code snippet
----------------------------
at this point, the word document file name is stored in string variable ls_doc_file

// Declare local Ole Word Doc Object
OLEObject ole_obj_word_doc

// instantiate the ole object
ole_obj_word_doc = CREATE oleobject

// connect to WORD app
li_retval = ole_obj_word_doc.ConnectToNewObject("word.application")
IF li_retval < 0 THEN
DESTROY ole_obj_word_doc
MessageBox("Connecting to COM Object Failed", &
"Error: " + String(li_retval))
Return
END IF

// open the file
ole_obj_word_doc.documents.open(ls_doc_file)

// Make the object visible and display the
ole_obj_word_doc.Application.Visible = True


// *********************************************
// These are commented out because I don't know
// when the user closes the file.
// *********************************************
// shut down the server
//??ole_obj_word_doc.quit()
// destroy the object
//??DESTROY ole_obj_word_doc
// *********************************************
 
You won't ever know when/if the user closes the word doc. About the only thing you can do is to issue a DisconnectObject command when the window/application closes. I wouldn't worry about using DESTROY as the garbage collection will take care of this.

Matt

"Nature forges everything on the anvil of time"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top