Firemonkey TNumberBox – new value not available until losing focus


Using a TNumberBox control (at least in Windows, probably other platforms too), when I type in a new value, and then press a button (TButton) to save the changes, upon reading the TNumberBox.Value property, it’s returning the original value before the edit was made. It turns out, this value is not accessible until after the control loses focus.

Now the button used to save changes, I have deliberately disabled its CanFocus property, along with all buttons in my app. This is because with the style I use (Jet), a focused button looks horrible (black text on dark gray background). Not to mention, on mobile platforms, focus is practically useless in my case.

Otherwise, if I don’t disable CanFocus on this save button, the focus is properly taken off of the TNumberBox and its Value property is okay. But, when disabling CanFocus on the save button, the focus is never taken off of this control, and therefore reading its Value property returns the old value.

How can I ensure the Value property returns the correct new value without changing the save button to CanFocus?

Enabling KillFocusOnReturn is not useful, because users would have to be aware they need to press “Return” or “Enter” which is not an option.


This problem also persists if you were to utilize the TNumberBox.OnChangeTracking event. I’m not sure how this event would be useful if you can’t even read the new value.

Comments are closed.