Am I the only one missing a "allow only numbers" setting in TEditBox lazarus / 31-LCL ---------------------------------------------------------------------- ArtLogi · 2016-01-20 05:35 Title says pretty much everything. I have found and figured out the routines to do so, in small scale. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if not (Key in ['0'..'9', '.', #8, #9]) then Key := #0; ..and many more so since this so common "challenge", as I have understood there is no problems in todays world. But this seems to be one thing that have been missing from basic libraries for what I can remember (with my almost nonexistent programming experience). I can't be the only one making programs that wants a numbers as an input. One only for integers with + / - One for Decimals with +/- and , or . Would be so convenient to just select the option from code inspector instead of using templates and copypasting and modifying. ---------------------------------------------------------------------- Leledumbo · 2016-01-20 05:42 Nah, that's far too limited. So something fancier is invented: http://wiki.lazarus.freepascal.org/jujiboutils ---------------------------------------------------------------------- ArtLogi · 2016-01-20 05:52 ..But simple is beautifull. ---------------------------------------------------------------------- fred · 2016-01-20 08:26 You could also try TMaskEdit in the Addinional tab ---------------------------------------------------------------------- wp · 2016-01-20 08:45 I don't like programs swallowing key presses. While typing numbers I often don't look at the screen, and I don't notice that something was wrong. Maybe I am entering the wrong decimal separator; if it is swallowed the entered number will be completely wrong - possibly unnoticed! It would be much better to accept all keys and display an error message when editing is done. ---------------------------------------------------------------------- ArtLogi · 2016-01-20 09:47 Mask edit is glumsy monster and also with totally different style. I'm not speaking about a form for thermo nuclear warhead launchcode input here, but typical "give value of formula / calculation""give amount of apples" type of thing. If I need to enter value of apples I have in my bucket then you can not wrote errorchecking that would a) make sure I didn't calculate the amount wrong while piling them from bucket to table, b) that I enter 500 instead of 501. Since the input is totally random inside some loose rules. Ie. must be cardinal and amount is below 10000k apples. Same for floats, give the peakvalue of current: Person could type -+1713.1321A or +-21.1321uA in same field, for such "idiot proof" errorcheck does not exist. For dates and ISBN numbers something like MaskBox fits and is designed, but for general shield for "numbers only field" it just doesn't seem to work too nicely and people are homebrewing error check routines etc. around Editbox, what professional programmers do I don't know. Maybe using external library or maybe there is something like this in ie. newest Delphi libraries. ---------------------------------------------------------------------- Bart · 2016-01-20 10:58 Quote from: ArtLogi on January 20, 2016, 06:35:56 amTitle says pretty much everything. I have found and figured out the routines to do so, in small scale. What is TEditBox? Quote from: ArtLogi on January 20, 2016, 06:35:56 amI can't be the only one making programs that wants a numbers as an input. There are T(FloatSpinEdit) and if you have trunk T(Float)SpinEditEx. They were designed for just this purpose. Mind you, users will still be able to paste anything into the control. (TMaskEdit prevents that (study the code to see how ugly that is), but in general is not the best control for your use case). For TEdit, if you only want integers (no floats) and you're on Windows, set NumbersOnly to True. This works also for TSpinEdit(Ex), and it will on this platform not allow pasting non-numbers into the control. Bart ---------------------------------------------------------------------- Bart · 2016-01-20 11:00 Quote from: ArtLogi on January 20, 2016, 06:35:56 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if not (Key in ['0'..'9', '.', #8, #9]) then Key := #0; You missed ^C, ^V, ^X and ^Z here (copy, paste, cut, undo)  Bart ---------------------------------------------------------------------- Thaddy · 2016-01-20 12:00 @Bart: That's why OnKeyUp and OnKeyDown also give you the shift state. In general it is better to write code that uses the key values + shift states than relying f.e. on OnKeyPress which gives you a char from a codepage. Better to do the mapping yourself. ---------------------------------------------------------------------- Nesto · 2016-01-20 12:21 windows ->  SetWindowLong(Edit1.Handle, GWL_STYLE, GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_NUMBER); ---------------------------------------------------------------------- Bart · 2016-01-20 12:53 Quote from: Thaddy on January 20, 2016, 01:00:48 pm@Bart: In general it is better to write code that uses the key values + shift states than relying f.e. on OnKeyPress which gives you a char from a codepage. Which is not relevant for characters inside the ASCII range. Bart ---------------------------------------------------------------------- Bart · 2016-01-20 12:54 Quote from: Nesto on January 20, 2016, 01:21:03 pmwindows ->  SetWindowLong(Edit1.Handle, GWL_STYLE, GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_NUMBER); What do you think do that TCustomEdit.NumbersOnly property does? Bart ---------------------------------------------------------------------- garlar27 · 2016-01-20 14:59 You can use TSpinEdit and TFloatSpinEdit in "Misc" tab.