Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 7260

[CONNECT C++] DialogItemHookHandler Lifetime

$
0
0

I found the DialogItemHookHandler and DialogHookHandler classes tucked away in a corner of the MicroStationAPI help doc.  They simplify the task of writing a dialog or dialog item hook (a.k.a. callback function).  The classes provides virtual callback methods that elegantly replace the switch statements we otherwise have to write in a hook function.

What's not clear is the lifetime management of a class that inherits from DialogItemHookHandler or DialogHookHandler.  The class is instantiated in the help examples by a static factory method...

static void HookResolve (DialogItemMessage *dimP)
{
  if (DITEM_MESSAGE_HOOKRESOLVE == dimP->messageType)
  {
    dimP->u.hookResolve.hookHandlerP = new MyItemHookHandler (dimP->db, dimP->dialogItemP);
    dimP->msgUnderstood = true;
  }
}

What is the lifetime of the Hook Handler created by that factory method?  Presumably it's destroyed when the dialog or item terminates.  But the destruction mechanism is not, as far as I can see, published.  Could I use an object that's instantiated elsewhere?  That is,

dimP->u.hookResolve.hookHandlerP = MyExistingHookHandler;
MyExistingHookHandler.SetPointers (dimP->db, dimP->dialogItemP);

But, if I do that, then the Hook Handler destruction mechanism will attempt to destroy something that it doesn't own.

Why do I ask this question?  Elegant though the new classes may be, then don't eliminate the distributed nature of dialog item functionality.  Some functionality is built-in to MDL dialog items.  Other functionality we add using these hook classes.  But, the classes remain distinct from one another.  For example, I have a dialog box that contains several dialog items.  I want to control the visibility of some items depending on the state of a ComboBox.  I have a DialogItemHookHandler class for the ComboBox and a DialogHookHandler for the dialog box.  On the ComboBox QueueCommand event, I tell the dialog to hide some items and reveal others.  That all works fine, but I'm having to use mdlDialog_xxx functions to send a message from the ComboBox handler to the DialogHookHandler.  That works, but I have two distinct classes filled with comments about who does what and to whom.

It would be useful to have, say, a class hierarchy that enabled me to say that the ComboBox handler class is subordinate or contained within the dialog handler class.  I don't see a way to do that right now.


Viewing all articles
Browse latest Browse all 7260

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>