Gord P 14 Posted February 25 I have not installed version 12 yet, but I am wondering if the TNumberBox control is still unable to recognize 'e' or 'E' (for exponent) when entering a number in the box when the mode is set to nbmFloat. Share this post Link to post
Uwe Raabe 2063 Posted February 25 The current Delphi 12 version doesn't support that out of the box. Share this post Link to post
Gord P 14 Posted February 25 (edited) Thanks Uwe. I should have put in a request a long time ago for it. I tried going back in to see if someone else had put a request in for that but couldn't login even though it said the site was in "read only" mode until the migration was completed. Currently, to ensure the user has entered a proper float value (allowing for 1.0E10 type of input) I simply handle it after the fact (i.e. after some OK button or CALC button or whatever has been clicked) by using TryStrToFloat() on the contents of the Text string from a basic TEdit and displaying a message if it is not a valid float. I would like to be able to do the checking while the value is being entered similar to what TNumberBox does in how it restricts the user to only using valid characters - except allowing for 'e' or 'E'. One challenge I see with that is that someone might incorrectly enter an 'e' at the end of the number (eg. "1.234E") which is not a valid float. Might have to just check OnExit but that might lead to awkward behavior. Anyway, just thinking out loud. Thanks again for checking. Edited February 25 by Gord P Share this post Link to post
Uwe Raabe 2063 Posted February 25 This is indeed very instable. One would need to extend the current internals significantly to make this work. Nevertheless one can achieve some results by setting AcceptExpressions to True and override these two methods: type TNumberBox = class(Vcl.NumberBox.TNumberBox) protected function GetValidCharSet(AAcceptExpressions: Boolean): TSysCharSet; override; function IsNumericText(const AText: string): Boolean; overload; override; end; function TNumberBox.GetValidCharSet(AAcceptExpressions: Boolean): TSysCharSet; begin Result := inherited GetValidCharSet(AAcceptExpressions); if Mode = nbmFloat then Result := Result + ['e', 'E', '+', '-']; end; function TNumberBox.IsNumericText(const AText: string): Boolean; begin Result := inherited; if AText.LastIndexOfAny(['e', 'E']) = AText.Length - 1 then Result := False; end; 1 Share this post Link to post
Gord P 14 Posted February 25 Thanks for that Uwe! I will take a look at that. Share this post Link to post