Life of member variables

D

David Taylor

I have a question about the lifetime of member variables in ThisDocument.
I'm trying to develop a solution which has its own custom menu (using
CommandBars to create the menu). In ThisDocument, I have two private member
variables mApp (Application) and m_mnuHeap (CommandBarPopup). In the
DocumentOpened event, I assign mApp to the global Application object, create
the custom menu, and assign mnuHeap to the menu. I sink the
Application.WindowActivated event with the following code:

Private Sub mApp_WindowActivated(ByVal Window As IVWindow)
If Window.Document Is ThisDocument Then
mnuHeap.Visible = True
Else
mnuHeap.Visible = False
End If
End Sub

The idea being to turn off the custom menu if the newly activated window
doesnt belong to ThisDocument, which works fine when I switch TO a new
document. However, when I try to switch BACK to my document, mnuHeap is
undefined. So, at some point the mnuHeap variable is destroyed. I find this
very strange, since mApp is not also destroyed (as evidenced by the event
firing!). Any ideas?

Thanks

Dave Taylor
PERI
 
M

Michael J. Hunter [MS]

Dave,

Chapter 22 of DVS
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devref/HTM
L/DVS_22_Customizing_the_Visio_UI_1256.asp) has all the gory details; search
for the section titled "Maintaining references to command bar controls when
contexts change".


Michael J. Hunter
Microsoft
michhu-at-online-dot-microsoft-dot-com

Developing Microsoft Visio Solutions:
http://msdn.microsoft.com/library/en-us/devref/HTML/DVS_Copyright_1270.asp
Developer Resources for Microsoft Visio:
http://msdn.microsoft.com/library/default.asp?url=/nhp/Default.asp?contentid=28000456

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 

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