V2KDSG Support:
Comments on
Deferring Event Handling
Home Visio V2KDSG V2KDSG Support This page

The following comments are summarized from a series of posts to the Visio Developer Forum. (That forum has been replaced by the Visio newsgroups.)

2000-02-07

EL:  I've learned not to do anything to Visio during the BeforeShapeDeleted event. If I want to do something as a result of a Shape being deleted, I queue a "transaction" and wait for the  following ShapesDeleted event, which will fire after one or more BeforeShapeDeleted events. Visio is in a fragile state during the BeforeShapeDeleted event and doesn't like to fiddled with.

[...]

SG: Following the question and the answer, I see that I ran into a very similar problem: I am trying to modify the ShapeSheet of a certain shape in the QueryCancelSelectionDelete and the SelectionDeleteCanceled events. When I try to modify any value in the ShapeSheet, I get a very similar exception to what you described  (86db0c9b)

EB: Here is a code snippet showing how I queue actions. The NoEventsPending fires once at the end of a sequence of events.

'-------------------------------------------------------------
'Code Snippet.......
Option Explicit

Dim WithEvents visApplication As Visio.Application
Dim QDeletedShapeActions As New Collection

'-----------------------------------------------------------
Private Sub Document_RunModeEntered(ByVal doc As IVDocument)
  Set visApplication = doc.Application
End Sub

'-------------------------------------------------------------------------
Private Sub Document_BeforeSelectionDelete(ByVal Selection As IVSelection)
Dim visShape As Visio.Shape

  For Each visShape In Selection
    QDeletedShapeActions.Add visShape.UniqueID(Visio.visGetOrMakeGUID)
  Next visShape
End Sub

'---------------------------------------------------------------------
Private Sub visApplication_NoEventsPending(ByVal app As IVApplication)
  While QDeletedShapeActions.Count
    'Do Something
    QDeletedShapeActions.Remove 1
  Wend
End Sub
'---------------------------------------------------------------------

DD: Marker events allow you to "queue" events to be handled when Visio reaches an idle state.

EL: It's true that MarkerEvents allow you to include text with the event. In fact, I was using this feature as my queuing mechanism; I'd do something like:

appObj.QueueMarkerEvent("this is the transaction")

I'd then simply run the "transaction" when the MarkerEvent fired, using the text to direct my actions. Pretty cool! Unfortunately, I found that Visio would sometimes drop the text from the MarkerEvent - the event would fire (the event numbers agreed) , but no text. This was disasterous for my application, because I needed to perform the action. I posted this problem on this Forum over a year ago, but
got no response. This was with 5.0c (which I'm still running). Maybe the problem's been addressed in V2K.

I ended up doing my own queuing using a Collection. With my own queuing method, I could wait to do some of the more complex "transactions" during the NoEventsPending or the even later VisioIsIdle events. I have different queues for each of these events.


Article Created: 2000-08-14 Last edit: Last edit: 00-09-30 Graham Wideman
Go to:
  DiagramAntics.com