Solved

Manipulating event sequencing

Posted on 2002-04-14
7
206 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now