What is the proper way to handle a yes/no Message Dialog when leaving a text field?

482 views Asked by At

My question title may be a bit misleading; if so, I apologize. I am unsure how better to title it.

I am attempting to add geocoding for address validation to a Delphi 7 form (built with CLX), and I'm running into a bit of a problem with it. The details are:

  • The user is expected to enter the data in the address fields in order - address, city, state, zip code.
  • Immediately upon leaving the zip code field, the address validation is to be called. (User specification.)
  • If the address comes back as not valid, the user is to be given a yes/no selection asking whether to correct the given address. (User specification)
  • If yes, reset focus to appropriate field (address, city, state, zip) as seen in the result from the geocoding api. Otherwise, proceed to next field.

Immediately after exiting the yes/no dialog, the behavior of the mouse seems to be a bit screwy. For one click, it looks as though the previous form (supposedly closed by this point) is instead receiving the focus - an on-click event on that form is capable of changing some of the values on this one (preloading of data), and those values will change if the mouse is clicked. Disabling the on-click event simply means that there is one mouse click that does nothing on the new form, then the click behavior returns to what is expected.

I've seen several things online while researching this; the consensus from these is that my problem is the conjunction of a Message Dialog inside the Zip Code field's OnExit event. (The MouseUp event seems to be getting lost between the two windows if I understand what I've read correctly.)

If I had my own way, I'd be including a manual button-press to run the validation. Given that end-user constraints bind me into a situation where I do not have that option, what is the best way to handle this situation?

1

There are 1 answers

0
Remy Lebeau On

Ideally, you could have the zip field's OnExit event use TThread.Queue() to delay the message dialog until after OnExit has exited first. Alas, TThread.Queue() was not introduced until Delphi 8. So OnExit will have to use an equivalent method, such as posting yourself a custom asynchronous message or starting a short one-time timer, to trigger the delayed action.