Trying to delete GoRectangle from null GoDocument

I have some confusion. I have items on the GoDocument and I want to implement a right-click delete. This works sporatically due to the following:


Me.Document.Remove(Me)

only works sometimes. For whatever reason, it fails due to:

Me.Document = Nothing ' Null Reference Exception
Not sure why I can still use/access this in some instances and in others the document reference is removed/nulled. Is there another way to safely access .Remove function when you don't have reference to the Document? I am familiar with the error, but not sure where the Document is being disposed/cleared.
As an FYI, the delete function is being initialize within the object (GoRectangle in this case).
Any thoughts would be helpful. And thanks as always.
dootndo2

The Document property in a GoObject isn’t always filled in. It’s best to use the GoView.Document property.

Wait – during initialization of an object, I wouldn’t expect any part of the node that you are building to be part of any GoDocument yet. It’s only after you have finished initialization and Add’ed it to some GoDocument (or some document’s GoLayer) that all of the parts of your node will have a non-null value for GoObject.Document.

If you want to remove some part of a group, just call GoObject.Remove(). Whether the group is part of a document or not won’t matter.