Recent

Author Topic: Numbers only or Integers only??? TEdit  (Read 1041 times)

edgarrod71

  • Jr. Member
  • **
  • Posts: 68
Numbers only or Integers only??? TEdit
« on: February 26, 2023, 06:07:25 pm »
Maybe I'm wrong but when I tried to put 3,1416 on a TEdit component with NumbersOnly property to True, it fails, it doesn't recognize the comma nor the dot. 

Trying to find inside the code I discovered that it only validates integers, so how can we modify things to make it work as Numbers definition would be?

in muistdctrls.pas line 1128 there are two string definitions for numbers, one for integer and the other one for float.  In lines below there's the procedure for validating... what should I change to make Edit accept Numbers (all of them, not Natural only) ;)

Blaazen

  • Hero Member
  • *****
  • Posts: 3234
  • POKE 54296,15
    • Eye-Candy Controls
Re: Numbers only or Integers only??? TEdit
« Reply #1 on: February 26, 2023, 06:36:44 pm »
Try TMaskEdit instead. Set EditMask to something like #,###.

BTW, didn't you edit the lazarus wiki about installing to MacOS in spanish?
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

edgarrod71

  • Jr. Member
  • **
  • Posts: 68
Re: Numbers only or Integers only??? TEdit
« Reply #2 on: February 26, 2023, 07:03:33 pm »
Yes, in my free time I try to help the free pascal community ;)  So I try to translate everything I can.  If I'm making mistakes, help me out...

Bart

  • Hero Member
  • *****
  • Posts: 4978
    • Bart en Mariska's Webstek
Re: Numbers only or Integers only??? TEdit
« Reply #3 on: February 26, 2023, 07:03:55 pm »
Maybe I'm wrong but when I tried to put 3,1416 on a TEdit component with NumbersOnly property to True, it fails, it doesn't recognize the comma nor the dot. 
...

 what should I change to make Edit accept Numbers (all of them, not Natural only) ;)

That's Windows for you.
Windows decided that NumbersOnly means only 0 to 9 and absolutely nothing else.
And since this was implemented as such, it had to behave the same on all widgetsets.

For floating point numbers: use a TFloatSpinEdit or TFloatSpinEditEx (or a TMaskEdit, but that looks a bit uglier, but it gives you absolute control over what can be types into and even pasted into it).

Bart

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1399
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Numbers only or Integers only??? TEdit
« Reply #4 on: February 26, 2023, 07:04:28 pm »
Just written in a hurry, for sure not final but a starting point.
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes , SysUtils , Forms , Controls , Graphics , Dialogs , StdCtrls;
  9.  
  10. type
  11.   TEdit = Class(StdCtrls.TEdit)
  12.     strict private
  13.       FRealNumbers: Boolean;
  14.     published
  15.       property RealNumbersOnly: Boolean read FRealNumbers write FRealNumbers;
  16.   end;
  17.  
  18.   { TForm1 }
  19.  
  20.   TForm1 = class(TForm)
  21.     Edit1: TEdit;
  22.     procedure Edit1Change(Sender: TObject);
  23.     procedure FormCreate(Sender: TObject);
  24.   strict private
  25.   private
  26.  
  27.   public
  28.  
  29.   end;
  30.  
  31. var
  32.   Form1: TForm1;
  33.  
  34. implementation
  35.  
  36. {$R *.lfm}
  37.  
  38. { TForm1 }
  39.  
  40. procedure TForm1.Edit1Change(Sender: TObject);
  41. var
  42.   i, ii: Integer;
  43.   d: Double;
  44.   s: string;
  45. begin
  46.   if Edit1.RealNumbersOnly then
  47.     begin
  48.       s := '';
  49.       if TryStrToInt(Edit1.Text, i) then
  50.         begin
  51.           s := IntToStr(i);
  52.           Edit1.Text := s;
  53.           Exit;
  54.         end;
  55.       if TryStrToFloat(Edit1.Text, d) then
  56.         begin
  57.           s := FloatToStrF(d, ffFixed, 16, 7);
  58.           Edit1.Text := s;
  59.           Exit;
  60.         end;
  61.       for i := 1 to Length(Edit1.Text) do
  62.         begin
  63.           if TryStrToInt(Edit1.Text[i], ii) then
  64.             s := s + Edit1.Text[i];
  65.           if Edit1.Text[i] = FormatSettings.DecimalSeparator then
  66.             s := s + FormatSettings.DecimalSeparator;
  67.         end;
  68.       Edit1.Text := s;
  69.     end;
  70. end;
  71.  
  72. procedure TForm1.FormCreate(Sender: TObject);
  73. begin
  74.   Edit1.RealNumbersOnly := True;
  75. end;
  76.  
  77. end.
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

Thaddy

  • Hero Member
  • *****
  • Posts: 12975
Re: Numbers only or Integers only??? TEdit
« Reply #5 on: February 26, 2023, 08:10:44 pm »
That's Windows for you.
Windows decided that NumbersOnly means only 0 to 9 and absolutely nothing else.
No, Bart. Numbers are numbers, not fractions of numbers. Basic math. Even Medical trained professionals know that! Period.
( You seem to have a bad weekend, btw)
Numbers do not include fractions, can not be irrational nor can be complex.
I am sure I forgot some more theory, but you get the point.
« Last Edit: February 26, 2023, 08:20:48 pm by Thaddy »
I actually get compliments for being rude... (well, Dutch, but that is the same)

Bart

  • Hero Member
  • *****
  • Posts: 4978
    • Bart en Mariska's Webstek
Re: Numbers only or Integers only??? TEdit
« Reply #6 on: February 26, 2023, 10:53:57 pm »
No, Bart. Numbers are numbers, not fractions of numbers. Basic math.
Not every word is math.
In the real world 1.2 is also a number.
Given that this is not the first report about this, it is obvious that the naming is a bit confusing to say the least.

Bart

wp

  • Hero Member
  • *****
  • Posts: 10866
Re: Numbers only or Integers only??? TEdit
« Reply #7 on: February 26, 2023, 11:01:07 pm »
No, Bart. Numbers are numbers, not fractions of numbers. Basic math. Even Medical trained professionals know that! Period.
( You seem to have a bad weekend, btw)
Numbers do not include fractions, can not be irrational nor can be complex.
Is this a joke?

dseligo

  • Hero Member
  • *****
  • Posts: 986
Re: Numbers only or Integers only??? TEdit
« Reply #8 on: February 26, 2023, 11:43:32 pm »
Numbers are numbers, not fractions of numbers.

You are mixing digits with numbers. Set your terminology straight.

dbannon

  • Hero Member
  • *****
  • Posts: 2455
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Numbers only or Integers only??? TEdit
« Reply #9 on: February 27, 2023, 12:22:47 am »

https://en.wikipedia.org/wiki/Number

In mathematics, the notion of a number has been extended over the centuries to include zero (0), negative numbers, rational numbers such as one half (1/ 2), real numbers such as the square root of 2 and complex numbers ....

Maybe the key words there are "over the centuries" ?  Thaddy, did they teach you about zero at school ?

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

GAN

  • Sr. Member
  • ****
  • Posts: 360
Re: Numbers only or Integers only??? TEdit
« Reply #10 on: February 27, 2023, 12:42:16 am »
Maybe I'm wrong but when I tried to put 3,1416 on a TEdit component with NumbersOnly property to True, it fails, it doesn't recognize the comma nor the dot. 

Trying to find inside the code I discovered that it only validates integers, so how can we modify things to make it work as Numbers definition would be?

in muistdctrls.pas line 1128 there are two string definitions for numbers, one for integer and the other one for float.  In lines below there's the procedure for validating... what should I change to make Edit accept Numbers (all of them, not Natural only) ;)

jujiboutils is another good option (and the one I use): https://wiki.lazarus.freepascal.org/jujiboutils/es
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

 

TinyPortal © 2005-2018