• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Manipulating event sequencing

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?
0
wamoz
Asked:
wamoz
1 Solution
 
MBoCommented:
I checked this problem with exit code in OnDeactivate of PSForm. All works fine.
0
 
JaccoCommented:
This is also not very beatiful but it worked for me:

procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
  TreeView1.SetFocus;
  // .. rest of the code
end;

Regards Jacco
0
 
wamozAuthor Commented:
MBo, there's some more pertinent info that I forgot to mention last time. The PS can be docked, and when it is docked, you don't get FormDeactivate events.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kretzschmarCommented:
add a condition-flag (boolean or integer)

just check set this on your editing

in your onchange-event check the flag,
if allowed, then do there your code,
otherwise not

or remove the event by assigning nil there,
and after your work reassign your event-procedure

meikl ;-)
0
 
Lee_NoverCommented:
how about 'Apply' and 'Cancel' buttons ? :)
you update all the data with the apply button
still the simplest solution would be as jacco suggested
eg OnMouseDown of the listview do Windows.SetFocus(ListView.Handle);
that should trigger the active controls exit event
0
 
MBoCommented:
Have you tried OnChanging treeview event?
0
 
pnh73Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept answer from Jacco

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now