I've been struggling with a bug and it came down to a spinner control. I've gleaned a lot from this community and thought I'd pass my solution along for comments/suggestions.
I am using a spinner control with the control source gnYear. Clicking on the up/down spinner arrows changes the value of what the spinner displays, but does not change the value of the control source. I verify this by displaying the control source gnYear in a wait window from the spinner's interactive change method. While the spinner control is still active, selecting a menu option to call a function that uses gnYear does not produce the desired results since gnYear remains at its initial value.
For example, gnYear is 2016 when the form loads. I change the spinner value to 2014. I immediately select a menu option to call a function that uses gnYear, but gnYear is still 2016, not 2014 as I would expect it to be. The value of gnYear is set to the correct value only when focus is set to another object. So my resolution is to setFocus to another object in the spinner's mouseLeave method.
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html ---
Generalizing this, a Control's .Value changes as you diddle with the display, but the control doesn't commit the .Value to the bound data until the Valid() returns .T., iow, you have a chance to validate the data. This is the normal flow of events when tabbing through controls, but doesn't catch all cases. This causes confusion when control moves outside of the form, as in your menu invocation, or when a Timer fires, or another screen pops up.
IIRC, without testing, frameworks I've work with do this generically with:
_VFP.ActiveForm.ActiveControl.SetFocus()
(yeah, unintuitively, setting focus to the control with focus causes it to cycle through a series of events like LostFocus(), Valid(), When() and GotFocus())
On Tue, Jan 19, 2016 at 3:48 PM, Richard Caruso rcaruso@acutedesigns.com wrote:
I've been struggling with a bug and it came down to a spinner control. I've gleaned a lot from this community and thought I'd pass my solution along for comments/suggestions.
I am using a spinner control with the control source gnYear. Clicking on the up/down spinner arrows changes the value of what the spinner displays, but does not change the value of the control source. I verify this by displaying the control source gnYear in a wait window from the spinner's interactive change method. While the spinner control is still active, selecting a menu option to call a function that uses gnYear does not produce the desired results since gnYear remains at its initial value.
For example, gnYear is 2016 when the form loads. I change the spinner value to 2014. I immediately select a menu option to call a function that uses gnYear, but gnYear is still 2016, not 2014 as I would expect it to be. The value of gnYear is set to the correct value only when focus is set to another object. So my resolution is to setFocus to another object in the spinner's mouseLeave method.
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html
[excessive quoting removed by server]
Thanks Ted, that was a huge help!
-----Original Message----- From: ProFox [mailto:profox-bounces@leafe.com] On Behalf Of Ted Roche Sent: Tuesday, January 19, 2016 3:57 PM To: profox@leafe.com Subject: Re: Spinner Control Anomaly
Generalizing this, a Control's .Value changes as you diddle with the display, but the control doesn't commit the .Value to the bound data until the Valid() returns .T., iow, you have a chance to validate the data. This is the normal flow of events when tabbing through controls, but doesn't catch all cases. This causes confusion when control moves outside of the form, as in your menu invocation, or when a Timer fires, or another screen pops up.
IIRC, without testing, frameworks I've work with do this generically with:
_VFP.ActiveForm.ActiveControl.SetFocus()
(yeah, unintuitively, setting focus to the control with focus causes it to cycle through a series of events like LostFocus(), Valid(), When() and GotFocus())
On Tue, Jan 19, 2016 at 3:48 PM, Richard Caruso rcaruso@acutedesigns.com wrote:
I've been struggling with a bug and it came down to a spinner control.
I've
gleaned a lot from this community and thought I'd pass my solution along
for
comments/suggestions.
I am using a spinner control with the control source gnYear. Clicking on
the
up/down spinner arrows changes the value of what the spinner displays, but does not change the value of the control source. I verify this by displaying the control source gnYear in a wait window from the spinner's interactive change method. While the spinner control is still active, selecting a menu option to call a function that uses gnYear does not
produce
the desired results since gnYear remains at its initial value.
For example, gnYear is 2016 when the form loads. I change the spinner
value
to 2014. I immediately select a menu option to call a function that uses gnYear, but gnYear is still 2016, not 2014 as I would expect it to be.
The
value of gnYear is set to the correct value only when focus is set to another object. So my resolution is to setFocus to another object in the spinner's mouseLeave method.
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html
[excessive quoting removed by server]