Hi Tim.
The reason why you noticed that the event fired twice (or more) is
most-likely because your code is adding the handler to the event
more than once, because that event does not fire more than once
for each selection.
From just a quick glance at your code, it seems that its adding the
event handler in the command method. But, it's never removed, so if
you execute that command 3 times, your event handler is added to
the event 3 times, and the event will fire 3 times for each selection.
If you execute the command 4 times, the event will fire 4 times for
each selection.
From another quick glance at it, your code seems to have much
bigger problems. You are caching references to DBobjects in the Tag
property of controls. Umm, can't do that.
A reference to a DBObject is only valid while the transaction it was
obtained from is active. Once that transaction ends, any DBObjects
obtained by calling GetObject() on the transaction, are no longer valid
and should not be used.
You never cache DBObjects for use at a later time, after the
transaction they were obtained from has ended. Doing that will
only lead to a fatal error.
ObjectId's are what you cache and use, not DBObjects. Try
storing the ObjectIds in a variable (or the tag property if you
wish), and then open the objects again using the ObjectId
when you need to access them.
Another problem your code has is that you are developing
it with an SDI mindset. As soon as you try opening more
than one document, then switching to another document
and clicking the Ok button on your tool, you will find that
your code is operating on the wrong document (not the
one containing the objects that you've previously cached
in the Control.Tag property), and kaboom.
Also, if your command method is run in multiple documents,
what do think is going to happen?
I'm afraid that developing an MDI-aware modeless user
interface is not as simple as it may at first appear from
afar.
Hi Tony,
Thanks for the responds.
In my testing I noticed that the event fired twice per selection, single window or single crossing or selection of a single object, without a command active, and I did notice that it fired each time I made a window. I noticed that it even fired when I hit escape to deselect all objects. I assumed that it would fire the same amount during a command also.
Maybe I can add some code to check to see if a command is issued, and if so ignore (or deactivate) my selection event. Thats a good idea.
I think I will change the code to kick you out once you have more than one block in the selection set, no need to keep checking unless I make it a multi-tab palette, one per block name with the amount in parenthesis. Just an idea.