Search code examples
c++buildervcl

NumbersOnly property of TEdit control


It is not clear from the documentation whether the NumbersOnly property set to "true" allows introducing numbers with the decimal separator. In my small test, I came to the conclusion that only integer numbers are allowed, but I am not sure about that, and am looking for a confirmation.


Solution

  • The NumbersOnly property sets/clears the ES_NUMBER style on the Edit's HWND handle:

    Allows only digits to be entered into the edit control. Note that, even with this set, it is still possible to paste non-digits into the edit control.

    So no, it does not allow the user to type a decimal separator, but the user can copy/paste one into the edit field.

    If you want the user to be able to type a decimal separator, do not set NumbersOnly to true, use the OnKey(Down|Up|Press) events instead to filter out unwanted keystrokes manually as needed.

    Otherwise, find a 3rd party Edit control that natively supports decimal number input. Many popular VCL component suites (TMS, DevExpress, etc) have custom Edit controls with more features than what the standard TEdit provides.