Manipulating event sequencing
Posted on 2002-04-14
My application maintains a tree full of nodes and a property sheet window (PS for brevity) that shows an appropriate editor for the object at which Node.Data points.
The TreeView Change event calls an Edit(Node) method on the PS form, which in turn loads the correct editor and gives it a reference to the object on which it should operate.
Each edit widget in a PS editor uses its Enter and Exit events to manage updates.
The problem occurs when the user edits a property and then clicks a different node in the tree without first moving focus off the edit widget.
The tree's change event fires BEFORE the edit widget's exit event. This sets a different object reference in the editor, so when the Exit event occurs the changes are written to the wrong object.
I have tried to no avail Application.ProcessMessages and Application.HandleMessage in the start of the tree's Change event handler.
Eventually [sic] I gave the PS form a FinaliseEditing method that calls the exit method explicitly and then sets a flag to prevent it from running again when the even is processed naturally.
This works, but, well, YUCK!
Any suggestions, people?