Gord P 14 Posted March 15, 2023 I typically use TEdits or StringGrids to let the user input numbers. Sometimes for a given input, the number can either a regular float (123.456) or required to be entered with scientific notation (1.23456e11). I thought maybe TNumberBox might be helpful with number input (i.e. automatically handle only entering valid numerics) so I checked it out but I am unable to get it to allow the user to enter an exponent. Based on something online I think the the Microsoft's NumberBox control, which I assume TNumberBox is emulating or wrapping, has the ability do this. Could be wrong here too though. Is it not able to do this or is it just me? I have fooled around with the DisplayFormat property but no joy. Share this post Link to post
programmerdelphi2k 237 Posted March 15, 2023 maybe.... Quote NumberBox1.Mode := TNumberBoxMode.nbmFloat; NumberBox1.Decimal := 0; // ?? NumberBox1.DisplayFormat := '0.0E+;0.0E-;Hello'; Share this post Link to post
Gord P 14 Posted March 16, 2023 Thanks for the suggestion. Unfortunately it doesn't give me the desired behavior. I would like the user to be able to enter a number such as 1.234E9. The NumberBox will not allow typing in an 'E'. Share this post Link to post
David Heffernan 2354 Posted March 16, 2023 What's wrong with a simple edit control? 1 Share this post Link to post
Uwe Raabe 2064 Posted March 16, 2023 3 hours ago, Gord P said: The NumberBox will not allow typing in an 'E'. Seems like a feature request in QP would be appropriate. 1 Share this post Link to post
Gord P 14 Posted March 16, 2023 7 hours ago, David Heffernan said: What's wrong with a simple edit control? Not too much really and that is what I have been using - along with some code to check or prevent incorrect input. I was just checking to see if the TNumberBox control would have that built in and maybe some additional features since the word "Number" is in the name of the control. Share this post Link to post
programmerdelphi2k 237 Posted March 16, 2023 (edited) maybe some like this ??? NOTE: when replace a value on NumberBox (old values) was verifyed that "e" will be accepted!!! then needs more tests... ok? NOTE2: NumberBox1.Text is always "old value", better works to "NumberBox1.VALUExxxxx" type TForm1 = class(TForm) NumberBox1: TNumberBox; procedure FormCreate(Sender: TObject); private procedure MyOnValidChar(AChar: char; var AValidated: boolean); public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin FormatSettings.DecimalSeparator := '.'; // NumberBox1.Mode := TNumberBoxMode.nbmFloat; NumberBox1.Decimal := 20; // ?? NumberBox1.DisplayFormat := '0.0E+;0.0E-;Hello'; // NumberBox1.OnValidateChar := MyOnValidChar; // <------ end; procedure TForm1.MyOnValidChar(AChar: char; var AValidated: boolean); begin if CharInSet(AChar, ['E', 'e']) then begin if NumberBox1.ValueFloat = 0 then // eNNNN.NNN ??? AValidated := false else AValidated := string(NumberBox1.Text).ToLower.CountChar('e') = 0; // NOT "Neeee" end; end; Edited March 16, 2023 by programmerdelphi2k Share this post Link to post
Gord P 14 Posted March 17, 2023 Thanks for that. In the end though if I have to add code, it's not much better than the Edit control for now. It's not a big deal, I was just wondering if I was missing something on this control, but I guess not. Share this post Link to post