Spurious "Requested operation is presently disabled" in Shape.Textsetter

K

Konrad Anton

Hello all,

I'm working on some kind of modelling tool where the user manipulates a
model (consisting of Entities and Associations between them, each coming
in several flavours) through a diagram (where Entity shapes are
represented by 2D shapes, e.g. squares, and Association shapes by 1D
connector shapes, e.g. arrows).

I'm using Visio 2007 Professional and VS2008, writing the add-in in C#
(if that matters).

When the user uses any 1D shape to connect two Entities, he expects the
shape to "become" an Association shape of the suitable flavour. If more
than one flavour is suitable, the add-in asks the user which flavour to
use. Sounds pretty feasible.

I've realised this using a ConnectAdded and a ConnectRemoved event handler.

* The ConnectAdded handler, given a Connect object, finds out which part
of the Connect is the 1D shape.

* For this shape, it checks if it is now connected to two Entity shapes
and hasn't been before (using something like a mapping from 1D shape's
Shape.GUID to a counter for the number of connected 2D shapes).

* If it is, the handler prompts the user about the flavour.

* It then drops a new Association shape from our stencil and copies
DoubleClick handler, Text(+) and ShapeData from old Association shape to
new Association shape.

* For each 2D shape connected to beginX or endX of the old 1D shape, it
glues the 2D shape to the beginX or endX of the new 1D shape.

* It deletes the old 1D shape.

Now the problem: when the user keeps on detaching a connector shape and
attaching it somewhere else, changing the flavour when prompted, then
after roughly 5 to 15 times, the Shape.Text of the newly dropped
connector shape is unwritable in (+), failing with a not-so-helpful
"Requested operation is presently disabled" COMException.

Last time I had such a problem, it was apparently caused by another
handler which asked an incoming Shape for its ID and its Document's ID.
When I deactivated that handler, the Shape.Text problem went away,
leaving me with the hypothesis that the .Document getter of the deleted
shape must have corrupted an internal data structure which wasn't used
until the next time Shape.Text was set.

Of course, I don't expect a complete solution from you, but perhaps
someone has had a similar problem, or notices that it's just forbidden
to drop shapes from an event handler or something.

Thanks in advance,
Konrad
 
K

Konrad Anton

Update:

I've noticed that using the Auto-Connect GUI action (clicking on the
blue triangles next to a shape) causes two ConnectAdded-events to be
sent. If I react on one ConnectAdded event with replacing the connector
shape being added, then the second ConnectAdded-event refers to a
deleted shape, and asking said deleted shape for its connections causes
silent corruption (almost as good as a "Forbidden use of deleted shape"
exception ;).

I've observed that the two ConnectAdded-events have subsequent event
sequence numbers. It works as a quick work-around, but is that something
I can count on?

--Konrad
 

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