Solved

Manipulating event sequencing

Posted on 2002-04-14
7
207 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

10 Experts available now in Live!

Get 1:1 Help Now