Solved

Manipulating event sequencing

Posted on 2002-04-14
7
208 Views
Last Modified: 2010-04-04
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
Comment
Question by:wamoz
7 Comments
 
LVL 1

Expert Comment

by:MBo
ID: 6941080
I checked this problem with exit code in OnDeactivate of PSForm. All works fine.
0
 
LVL 10

Accepted Solution

by:
Jacco earned 200 total points
ID: 6941170
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
 
LVL 1

Author Comment

by:wamoz
ID: 6941210
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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 27

Expert Comment

by:kretzschmar
ID: 6941257
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
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6941515
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
 
LVL 1

Expert Comment

by:MBo
ID: 6941828
Have you tried OnChanging treeview event?
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9003214
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question