Detecting a closed document

A

Allov

Hi,

I'm having trouble detecting if a document has been closed using .Net and
the Word Object Library 12.0.

Imagine a wraper for the :

Public Class WordWraper

Private word As New Word.Application()
Private doc As Word.Document = word.Documents.Open("C:\test.doc")

Public Sub SaveAndClose()
doc.Save()
doc.Close()
End Sub

Public Sub Dispose(...)
' Some verification of the object to check if it exists or not equals
nothing.
doc.Close() ' Here, it will crash with error RPC_E_DISCONNECTED.
doc = Nothing
End Sub

End Class

In the dispose method, it's going to crash if the object has been closed
before. I could put a flag "hasBeenClosed" in this class and test this flag
before doing the last close operation, but I'm hoping there's a way to check
for that in the API itself?

Thanks a lot
Allov
 
A

Allov

Yeah, I wasn't clear enough with my comment, should have put the check for
null values.

So, yeah, I do check for Nothing, and this is why I'm asking for a solution
here because the object does NOT equal nothing when it has been closed, and
when I try to close it a *second* time (like in the dispose function), it
gives me the mentionned errorl.

So the code should read:

If doc IsNot Nothing Then doc.Close() ' <-- Crashes when closing a second
time.
doc = Nothing
 
T

Tony Jollans

I don't know the syntax of whatever language you are using so will have to
assume that is correct.

The most common reason for this sort of problem is implicit instantiation
somewhere. To identify where that might be we would need to see all the
code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top