the onexit of the editbox, not of the form right? (just checking)
Main Topics
Browse All TopicsOkay, the problem is simple but for whatever reason I failed to find a good solution for some annoying problem...
I have a form with several editboxes on them. There are also several menu-options, speedbuttons and other controls on it. What I want is when an user enters some text in an editbox and then focuses on another field then an event (OnExit) needs to be triggered which will call for an update of several other fields. Since I'm dealing with a calculation that might take half a second or more because it requires intensive database access, I cannot just use the OnChange method for this.
Right now I use the OnExit event combined with the OnKey event. (The last when the user presses the Enter or Tab key.) But this solution just feels funny.So, are there any better solutions?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
onexit should be sufficient for tab as well ;) only the enter needs special processing.
that is the way I would do it as well.
I don't know about better, but you can look at application events. I personally didn't worked too much with it as the events from control are more than enough for my UI-programming.
Actually, it is not... If you click on the speedbutton it doesn't seem to get triggered. At least not with Delphi 6.
Problem is, the click on the speedbutton might require the calculation to be executed again. Of course every speedbutton event could trigger the Calculations in it's own OnClick event but that too is a bit clumsy in my opinion.
Most controls will make sure the OnExit of the editcontrol is triggered. But with menu-options and speedbuttons this event does NOT get triggered. And I need some event to be triggered whenever the user changes the focus to somewhere else. It has to do with the fact that a speedbutton is no TWinControl and thus it can't get focus. Thus, the edit control never loses focus and is thus never really exited.
It gets even more interesting when you realise that the OnExit method is triggered by the CM_EXIT message. This message is sent to the focused control when the form gets information that the focused control is about to change.
So the trick that I am looking for is some event or message that gets called whenever the user does something to another control. Especially if it is a control that cannot receive focus.
The work done on processing cannot be done faster, unfortunately. Actually, since more is going to be added, it's actually becoming even slower but no problem... The user sees an hourglass. :-) (And hopefully the user has the related Access database on his local machine and not on some other system that's only accessible by a 10 mbit network with all other kinds of slowing factors...)
Basically, I am trying to improve the performance of an older project while we're also working on a newer version of this product. The newer version will have everything it needs in-memory thus it performs a lot faster. But it's expected to be finished in 2007. So I like to improve the speed of the old version a bit, which we would like to be ready at the end of this month... Stupid deadlines... :-)
> Problem is, the click on the speedbutton might require the calculation to be executed again. Of course every speedbutton event could trigger the Calculations in it's own OnClick event but that too is a bit clumsy in my opinion.
Well really there is no reason to have an OnExit event for a speedbutton, thats why it has an OnClick event.
You wouldnt code a button to do nothing when you click it, but to fire off an event when you leave its area, that is very clumsy and unnecessary.
This is why you split out calculations to be called from a routine that many events can use, its the right thing to do.
Sorry, mike... The trouble is that a click on a non-TWinControl is triggering some actions but I need the calculations to be done at that moment too! At the moment e.g. the SpeedButton is clicked, I'd like to perform the same action as on the OnExit event. Since I use quite a few speedbuttons and other controls that cannot receive focus, I need a more generic solution. Either something for on the form or a modification that can be applied to the TEditControl class. (I am using a custom-made editcontrol for my project with some additional functionality which makes it impossible to use alternative third-party solutions for this problem.)
This is maybe too circumstantial but it would work I think...
You could have a dummy-component (let's say a small panel w/o broders in backgr. color). Every windowed component that receives focus stores it's handle in the dummy-panel's tag property. Every speedbutton that_s being clicked first calls a procedure that sets the focus on the dummypanel and immediately on the component who's handle is stored in the dummy-panel's tag property. So the focus owner would lose focus only for a fraction of a second, but enough to fire it's OnExit...
Hi,
My 2 cents in another idea:
The basic thought is that the user can do all things that do NOT fire OnExit events using mouse only.
So, the isea is :
1. to capture mouse click event on form level (in WndProc, processing WM_LBUTTONDOWN, WM_RBUTTONDOWN, etc. messages, for instance);
2. to get the control (TControl descendants only, I think) under the mouse;
3. to compare it with the control, having the focus;
4. and, if they don't match, to fire the appropriate OnExit event.
I don't have Delphi at hand to test anything. A problem might be if these controls like your speedbuttons and menu items cannot be discovered in step 2. above. Another problem might be when, even if you succeed in all steps, your button click gets fired first and then onexit event. It will be funny - all efforts for nothing. It will not worth even 2 cents then :-)
Best regards, Geo
Well, thing is that I can simply solve this by calling the calculation method for every speedbutton or menuoption that gets clicked. But this is the situation that I'm trying to avoid here.
I do have one alternative solution, which is by defining my own speedbutton class which is either inherited from TWinControl or which sends an OnExit message to the active control, followed by an OnEnter message, every time it gets clicked. Still leaves me with the menu-options and shortcut keys, which also behave in this way.
Geo is suggesting a good point here, although I must avoid having to perform this calculation too often. In the current situation, the calculation is called on the OnChange event which actually results in the user typing a character, then waiting half a second, then type another character, wait some more, etc. (And the worst thing is that the calculation is calling ProcessMessages itself to keep the application responsive, meaning that the next OnChange event can actually occur while it is processing an OnChange event!)
Basically, I need a more reliable method which won't get triggered as often as the OnChange event...
I considered using an ActionList, btw. Unfortunately that too would cost too much time since too many options would have to be changed to TActions...
Hi Alex,
I will try to extend WndProc solution a bit. Perhaps you may capture all situations requiring recalculation there - focus changes instead of using OnExit events, mouse down events outside the rectangle of the TWinControl descendant, which currently holds the focus (speedbuttins, menu items), shortcut keys, etc. Everything will be in one place, centralized and definately easy for maintenance. That procedure gets called before sending the events to the corresponding controls, as far as I remember.
Another solution could be a change in user's interface. Add a recalculation button and let the user decide when to perform that operation. It is not a programming solution and most probably is not possible in your case. Just wanted to mention it as an option.
Regads, Geo
Business Accounts
Answer for Membership
by: mokulePosted on 2006-09-07 at 05:55:20ID: 17470452
I must misunderstand something. OnExit is fired normally so where is the problem?