TJvValidateEdit performs its min and max value validation as part of its FocusKilled (WM_KILLFOCUS) handler. However, as explained by Raymond Chen in http://blogs.msdn.com/b/oldnewthing/archive/2004/04/19/115912.aspx, [^] this is the wrong place to do validation. In particular, pressing Enter to close a dialog with an OK button never triggers FocusKilled, so TJvValidateEdit.Value can have an invalid value if it's read during the OK button's Click event.

The best fix I can think of is for reading the Value property to trigger the same canonicalize-and-validate logic that FocusKilled does. This should only happen during normal runtime, so I believe this should only be done if ComponentState does not include csDesigning or csWriting.

Does this sound reasonable? Are there potential issues or complications that I'm missing? If so, I can submit a pull request.

Please provide the zipped sources of a sample application showing this

(0021207)
jkelley (reporter)2015-09-14 22:16

1. Run the attached sample application.
2. Click the Test button to open the modal dialog.
3. Enter a value of -1, which is below the configured MinValue of 0.
4. *Click* the OK button. Note that the message box displays the correctly enforced minimum value of 0, and the edit is set back to 0.
5. Click the Test button again to reopen the modal dialog.
6. Reenter a value of -1.
7. Without clicking anywhere or changing the keyboard focus, *press Enter* to activate the default OK button. Note that the message box displays an invalid value of -1, although the edit is set back to 0.

(0021753)
mh (reporter)2019-04-26 20:34

I'd say your description and how you plan to fix it is worth a try! Please create that pull request suggested!