Recent

Author Topic: Feature request: allow decimal separator from numeric keypad in TDbEdit  (Read 5803 times)

stephanie

  • New Member
  • *
  • Posts: 27
Hello,

TDbEdit, in the numeric fields, doesn't allow the decimal separator key from the numeric keypad, if the country of the keyboard has thousand separator and not decimal separator in the numeric keypad.

For example, the italian keyboard has "." in the numeric keypad, but the decimal separator is ",". I believe that, in this case, the "." should be converted in ",", in order to digit correctly numbers with float. This is already made from other software, e.g. LibreOffice on Calc.

With the german keyboard there are no problems, on the numeric keypad there is "," und all works correctly.

I think that perhaps the code of the LCL/include/dbedit.inc schould be changed in the procedure TDBEdit.UTF8KeyPress adding:

if (CharKey = ThousandSeparator) and (FDataLink.Field.DataType in [FtFloat, ftCurrency, ftBCD]) then UTF8Key := DecimalSeparator;

I haven't tested this code, may be there are better solutions (a new property?), but I think this is very important in some countries.

Sorry for my bad english.

Best regards,

Stephanie


JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Feature request: allow decimal separator from numeric keypad in TDbEdit
« Reply #1 on: August 31, 2017, 07:24:53 pm »
If you can work out a good solution, please provide a patch.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Feature request: allow decimal separator from numeric keypad in TDbEdit
« Reply #2 on: August 31, 2017, 08:24:52 pm »
You need to add unit clocale to *.lpr file and your project will use your system settings (decimal separator, date format etc.).
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/

stephanie

  • New Member
  • *
  • Posts: 27
Re: Feature request: allow decimal separator from numeric keypad in TDbEdit
« Reply #3 on: August 31, 2017, 09:23:56 pm »
Hello,

applying this line at the begin of the KeyPress event of the lcl/include/dbedit.inc seems to work:

Code: Pascal  [Select][+][-]
  1. if (UTF8Key = ThousandSeparator) and (FDataLink.Field.DataType in [FtFloat, ftCurrency, ftBCD]) then UTF8Key := DecimalSeparator;

Here the full code of the KeyPress event:

Code: Pascal  [Select][+][-]
  1. procedure TDBEdit.UTF8KeyPress(var UTF8Key: TUTF8Char);
  2. var
  3.   CharKey: Char;
  4. begin
  5.   inherited UTF8KeyPress(UTF8Key);
  6.   //If the pressed key is unicode then map the char to #255
  7.   //Necessary to keep the TField.IsValidChar check
  8.  
  9.   //Convert thousand separator in decimal separator (in some contries in the numeric keypad thers is the thousand separator)
  10.   if (UTF8Key = ThousandSeparator) and (FDataLink.Field.DataType in [FtFloat, ftCurrency, ftBCD]) then UTF8Key := DecimalSeparator;
  11.  
  12.   if Length(UTF8Key) = 1 then
  13.     CharKey := UTF8Key[1]
  14.   else
  15.     CharKey := #255;
  16.  
  17.   //handle standard keys
  18.   if CharKey in [#32..#255] then
  19.   begin
  20.     if not FieldCanAcceptKey(FDataLink.Field, CharKey) or not FDatalink.Edit then
  21.       UTF8Key := '';
  22.   end;
  23. end;
  24.  

Local settings are ok, the problem is that in some countries, e.g. Italy, in the numeric keypad there is the thousand separator and not the decimal separator (!), the user schould select antother keyboard (e.g. Italy 142 and not Italy 141 that is default) or customize the keyboard, this patch make all easier, the thousand separator is in any case converted as decimal separator with float fields.

Sorry for my bad english.

Best regards,

Stephanie

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Feature request: allow decimal separator from numeric keypad in TDbEdit
« Reply #4 on: August 31, 2017, 09:28:58 pm »
And what if the user wants to input a thousand separator?

Ondrej Pokorny

  • Full Member
  • ***
  • Posts: 220
Re: Feature request: allow decimal separator from numeric keypad in TDbEdit
« Reply #5 on: August 31, 2017, 09:37:23 pm »
Don't forget that in some countries (CZ) the thousand separator is a space character and not the dot. Better would be:

Code: [Select]
if ((UTF8Key = '.') or (UTF8Key = ',')) and (FDataLink.Field.DataType in [FtFloat, ftCurrency, ftBCD]) then UTF8Key := DecimalSeparator;

And what if the user wants to input a thousand separator?

Although I didn't test DBEdit, StrToFloat doesn't like ThousandSeparators:

Code: [Select]
  x := StrToFloat('1'+ThousandSeparator+'000'+DecimalSeparator+'10');

raises an exception. So for me the patch absolutely OK.

stephanie

  • New Member
  • *
  • Posts: 27
Re: Feature request: allow decimal separator from numeric keypad in TDbEdit
« Reply #6 on: August 31, 2017, 09:46:14 pm »
And what if the user wants to input a thousand separator?

I dont't think that the user has to insert a thousand separator in a TFloatField. In any case thousand separator weren't allowed, FieldCanAcceptKey returns fals on TFloatField so UTF8Key is setted = ''. And this is the problem, because I cannot intercept the key in the KeyPress event.

Maybe is schould be possibile to change the code also in this way:

Code: Pascal  [Select][+][-]
  1. if not FieldCanAcceptKey(FDataLink.Field, CharKey) or not FDatalink.Edit then begin
  2.       if (UTF8Key = ThousandSeparator) and (FDataLink.Field.DataType in [FtFloat, ftCurrency, ftBCD]) then UTF8Key := DecimalSeparator else UTF8Key := '';
  3. end;

so the convert happen only if Key is setted to ''.

But I think the convert at the begin of the KeyPress event is also ok.

In TFloatField the user can insert only digits and decimal separator.

Best regards,

Stephanie

stephanie

  • New Member
  • *
  • Posts: 27
Re: Feature request: allow decimal separator from numeric keypad in TDbEdit
« Reply #7 on: August 31, 2017, 09:50:02 pm »
Don't forget that in some countries (CZ) the thousand separator is a space character and not the dot. Better would be:

Code: [Select]
if ((UTF8Key = '.') or (UTF8Key = ',')) and (FDataLink.Field.DataType in [FtFloat, ftCurrency, ftBCD]) then UTF8Key := DecimalSeparator;


Thanks for the information, I agree, so the patch schould be ok.

Best regards,

Stephanie

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Feature request: allow decimal separator from numeric keypad in TDbEdit
« Reply #8 on: September 07, 2017, 03:16:50 pm »
And what if the user wants to input a thousand separator?
Although I didn't test DBEdit, StrToFloat doesn't like ThousandSeparators:

Code: [Select]
  x := StrToFloat('1'+ThousandSeparator+'000'+DecimalSeparator+'10');

raises an exception. So for me the patch absolutely OK.
That's another story which should be fixed independently. Just imagine people having to enter large numbers: for them a thousand separator is extremely important to validate the input.

If the decimal separator is a comma (,) and the thousand separator is a point (.) and the user wants to enter 1 million with two decimal places and types "1.000.000,12" the resulting string is meaningless numerically: 1,000,000,12

To me mixing up decimal and thousand separators is a no-go.
« Last Edit: September 07, 2017, 03:23:18 pm by wp »

stephanie

  • New Member
  • *
  • Posts: 27
Re: Feature request: allow decimal separator from numeric keypad in TDbEdit
« Reply #9 on: September 07, 2017, 03:33:24 pm »
And what if the user wants to input a thousand separator?
Although I didn't test DBEdit, StrToFloat doesn't like ThousandSeparators:

Code: [Select]
  x := StrToFloat('1'+ThousandSeparator+'000'+DecimalSeparator+'10');

raises an exception. So for me the patch absolutely OK.
That's another story which should be fixed independently. Just imagine people having to enter large numbers: for them a thousand separator is extremely important to validate the input.

If the decimal separator is a comma (,) and the thousand separator is a point (.) and the user wants to enter 1 million with two decimal places and types "1.000.000,12" the resulting string is meaningless numerically: 1,000,000,12

To me mixing up decimal and thousand separators is a no-go.

I understand, but how to do with the keyboards that haven't the decimal separator in the numeric keypad? From the numeric keypad the user should be able to digit numbers, and this is not possibile when from the numeric keypad there is no way to digit the decimal separator.

Unfortunately the KeyPress event can't allow to know if the key comes from the keyboard or the numeric keypad.

May be the solution can be a new property that allows or not to convert the separator in the numeric keypad into the decimal separator.

Best regards,

Stephanie



wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Feature request: allow decimal separator from numeric keypad in TDbEdit
« Reply #10 on: September 07, 2017, 03:48:43 pm »
Aren't there drivers or scripts somewhere in the internet to fix this deficiency on your computer? For example, look at the posts in this thread: https://superuser.com/questions/747250/dot-instead-of-comma-on-numerical-keyboard

A property to switch this behavior off is the least I would expect. But probably it will make things even more complicated because the user always has to be aware of he is working with a program which respects the numeric keypad decimal separator or not. On a system-wide change, all programs behave the same.

stephanie

  • New Member
  • *
  • Posts: 27
Re: Feature request: allow decimal separator from numeric keypad in TDbEdit
« Reply #11 on: September 07, 2017, 04:40:40 pm »
Hello, I've replied also in the bug tracker, the problem is that the program muss be used from the user, they are customised to use the numeric keypad und change keyboard create problems: 1. it is necessary to say to each user; 2. A different keyboard is a little different with some characters.

I use the german keyboard, there are no problems. But we have user in Italy that have keyboard IT 101 with .  in the numeric keypad, and in Italy the decimal separator is , .

With the old version of Lazarus, there were no filter, the user could insert "," now the char is refused in the KeyPress event of TDbEdit, so I cannot work in the KeyPress event of my code.

So, as the "," is refused, I think that convert it in the decimal separator makes no problems.

When the "," will be accepted in order to allow insert numbers even with thousand separator, ok, I can use the KeyEvent, as with the old version of Lazarus, but now the user cannot insert "," in a numeric TDbEdit (Currency Field).

Best regards,

Stephanie

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Feature request: allow decimal separator from numeric keypad in TDbEdit
« Reply #12 on: September 07, 2017, 05:39:16 pm »
I don't know when this was introduced, but I found that TField has a public property ValidChars. If you add the '.' to this set then you can trap this key in the OnUTF8KeyPress event.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   i: Integer;
  4. begin
  5.   BufDataset1.CreateDataset;
  6.   Bufdataset1.Fields[1].ValidChars := BufDataset1.Fields[1].ValidChars + ['.', ','];
  7.   BufDataset1.Active := True;
  8.   for i := 0 to 9 do begin
  9.     BufDataset1.Insert;
  10.     BufDataset1.Fields[0].AsString := 'Item' + IntToStr(i);
  11.     Bufdataset1.Fields[1].AsFloat := Random*100;
  12.   end;
  13. end;
  14.  
  15. procedure TForm1.DBEdit1UTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
  16. begin
  17.   if UTF8Key = '.' then UTF8Key := ',';
  18. end;
« Last Edit: September 07, 2017, 05:44:47 pm by wp »

stephanie

  • New Member
  • *
  • Posts: 27
Re: Feature request: allow decimal separator from numeric keypad in TDbEdit
« Reply #13 on: September 08, 2017, 11:57:55 pm »
I don't know when this was introduced, but I found that TField has a public property ValidChars. If you add the '.' to this set then you can trap this key in the OnUTF8KeyPress event.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   i: Integer;
  4. begin
  5.   BufDataset1.CreateDataset;
  6.   Bufdataset1.Fields[1].ValidChars := BufDataset1.Fields[1].ValidChars + ['.', ','];
  7.   BufDataset1.Active := True;
  8.   for i := 0 to 9 do begin
  9.     BufDataset1.Insert;
  10.     BufDataset1.Fields[0].AsString := 'Item' + IntToStr(i);
  11.     Bufdataset1.Fields[1].AsFloat := Random*100;
  12.   end;
  13. end;
  14.  
  15. procedure TForm1.DBEdit1UTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
  16. begin
  17.   if UTF8Key = '.' then UTF8Key := ',';
  18. end;

Thanks, the property ValidChars is very useful in this case.

Anyway, a (new) property in data-aware components would be easier to use, who wants can set the property to True and don't need to write other code and don't have to force to allow other chars, as the problem is the keyboard of some countries ( (it is normal that in Italy "," is allowed and not ".", the problem is the numeric keypad of the italian keyboard) .

I think that for many countries a property like this would be appreciated, and not only for TDbEdit. Several countries need to convert the input for numbers., so I think generally to data-aware components.

However the ValdiChars property allows to solve the problem, thank you very much.

Thank you again,

Stephanie

 

TinyPortal © 2005-2018