Question

Triggering the OnExit...

Asked by: Workshop_Alex

Okay, 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.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-09-07 at 05:42:32ID21981022
Tags

onexit

Topic

Delphi Programming

Participating Experts
6
Points
500
Comments
16

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. How to avoid OnKeyDown fires OnExit procedure
    I write codes in the Edit box OnExit event and OnKeyDown event. the OnKeyDown procedure likes begin if Key = VK_F4 then F4AutoClick(CmbDeptFrom, edtDeptFrom); end Problem is when I press F4, it fires OnExit procedure first, but I don't want OnExit fired. How can I solv...
  2. finding out why onExit occurs
    I need something "behind-the-scenes" probably. I have a form with a lot of visual components. Among these components are tedits and tbitbtns. What I want to do is, inside an onExit event handler, to determine why the tedit is loosing focus, is it because the user pr...
  3. OnExit *before* the ActiveControl is changed?
    TStringGrid's OnExit-event happens only after the form's ActiveControl is changed. Is it possible to write code that is executed before ActiveControl is changed? Somekind of OnExit-event that occurs *before* ActiveControl changes? I'm not going to even try to explain why I n...
  4. Focus on edit control after OnExit
    Hi, I have a derived control from TBoxControl. The derived control acts like an edit control and I have an OnExit event. In the OnExit procedure I validate the user input and open a message box if the input is not valid. After I close the message box the focus is not visib...
  5. OnExit eats up mouseup event for new control when showi…
    The problem can be replicated easily. place 3 tedits on a form. write a showmessage('exit') in edit1's onexit event run the program give edit1 focus use the mouse to give edit3 focus, click ok to the showmessage observe how you can't write anything in edit3 now, until you cl...
  6. Preserve trailing whitespace OnExit?
    Is it possible to preserve any trailing whitespace in an Access 2000 textbox after update? I have tracked the length of the textbox, and Access seems to automatically strip whitespace between "AfterUpdate," and "OnExit." I need to preserve this space in m...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

by: mokulePosted on 2006-09-07 at 05:55:20ID: 17470452

I must misunderstand something. OnExit is fired normally so where is the problem?

 

by: LimbeckPosted on 2006-09-07 at 05:57:09ID: 17470467

the onexit of the editbox, not of the form right? (just checking)

 

by: ciulyPosted on 2006-09-07 at 05:58:15ID: 17470478

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.

 

by: LimbeckPosted on 2006-09-07 at 05:58:35ID: 17470481

oh ok, ive made brighter remarks, i admit it

 

by: mikelittlewoodPosted on 2006-09-07 at 06:03:48ID: 17470529

I would stick to the OnExit event, and process the Enter button separately as well.
It might be an idea though to see if you can speed up the work being done on processing.
Is there anyway to store more data locally instead to use the OnChange event or is this not a viable option?

 

by: Workshop_AlexPosted on 2006-09-07 at 06:12:30ID: 17470612

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.

 

by: Workshop_AlexPosted on 2006-09-07 at 06:22:33ID: 17470734

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... :-)

 

by: mikelittlewoodPosted on 2006-09-07 at 08:17:32ID: 17471759

> 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.

 

by: mikelittlewoodPosted on 2006-09-07 at 08:24:40ID: 17471813

Could you just instead trigger the OnExit button of last wincontrol component on click of button?

Have a global variable storing last enter/exit of wincontrol, then cast the control to use its OnExit event.
Just a thought.

 

by: Workshop_AlexPosted on 2006-09-07 at 08:35:20ID: 17471922

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.)

 

by: TNamePosted on 2006-09-07 at 10:16:26ID: 17472925

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...

 

by: TNamePosted on 2006-09-07 at 10:23:52ID: 17472990

Not very different from mikelittlewood idea, is it? Ok, then same objection, I guess...

 

by: geobulPosted on 2006-09-07 at 12:55:14ID: 17474159

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

 

by: Workshop_AlexPosted on 2006-09-08 at 00:01:40ID: 17477418

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...

 

by: Workshop_AlexPosted on 2006-10-10 at 23:56:07ID: 17704859

Am just waiting a bit more in case someone has the perfexct solution. Otherwise, the points will be split.

 

by: geobulPosted on 2006-10-14 at 05:47:00ID: 17730320

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

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...