Recent

Author Topic: TEdit with "FloatOnly"?  (Read 1291 times)

winni

  • Hero Member
  • *****
  • Posts: 1786
Re: TEdit with "FloatOnly"?
« Reply #15 on: August 03, 2020, 11:43:47 pm »

At what point does a Double not have enough digits to represent a large (integer) value?

Bart

MaxIn64 needs a maximum of 19 digits: 9223372028264841218

Double shows a maximum of 16 digits, sometimes only 15.

Winni

Jvan

  • Full Member
  • ***
  • Posts: 108
Re: TEdit with "FloatOnly"?
« Reply #16 on: August 03, 2020, 11:59:41 pm »
Alternatively, you may want to try TFloatSpinEdit, which is on Misc tab.

Or TFloatSpinEditEx on the LazControls tab which has additional useful properties:
  • UpDownVisible - false hides the updown buttons
  • ArrowKeys - false disables incrementing/decrementing the value by the arrow keys; the controls behaves more like a normal TEdit
  • DecimalSeparator - point or comma (or anything else)
  • text automatically right-aligned
  • NullValue, NullValueBehaviour - specifies what happens when field is empty
  • Layout - move spin buttons to the left
and more...

Hi

How can I set the decimal separator of Windows by default? I ask it because it has "." by default. Something like:
Code: Pascal  [Select][+][-]
  1.  FloatSpinEditEx1.DecimalSeparator := ¿WindowsSeparator?

Well... I did it that way:
Code: Pascal  [Select][+][-]
  1. var
  2.   decSep: Char;
  3. begin
  4.   decSep := FormatFloat('0.0', 0)[2];
  5.   FloatSpinEditEx1.DecimalSeparator := decSep;  
  6. end
  7.  
« Last Edit: August 04, 2020, 12:02:36 am by Jvan »

Zoran

  • Hero Member
  • *****
  • Posts: 1589
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TEdit with "FloatOnly"?
« Reply #17 on: August 04, 2020, 12:07:11 am »
Well... I did it that way:
Code: Pascal  [Select][+][-]
  1. var
  2.   decSep: Char;
  3. begin
  4.   decSep := FormatFloat('0.0', 0)[2];
  5.   numMovMntD.DecimalSeparator := decSep;  
  6. end
  7.  

You can use DefaultFormatSettings.DecimalSeparator from SysUtils.
Code: Pascal  [Select][+][-]
  1. numMovMntD.DecimalSeparator := DefaultFormatSettings.DecimalSeparator;

Jvan

  • Full Member
  • ***
  • Posts: 108
Re: TEdit with "FloatOnly"?
« Reply #18 on: August 04, 2020, 12:09:39 am »
Thanks.

Zoran

  • Hero Member
  • *****
  • Posts: 1589
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TEdit with "FloatOnly"?
« Reply #19 on: August 04, 2020, 12:19:26 am »
Just note -- DefaultFormatSettings should be initialized to your system defaults on application start.

On Windows it is done automatically.
However, on Linux (or other unixes), you need to include clocale unit in your lpr file, near the top of uses section.

See here: https://www.freepascal.org/docs-html/current/rtl/clocale/index.html

So, add:
Code: Pascal  [Select][+][-]
  1. {$ifdef unix}clocale,{$endif}
on top of uses section in your main program file.

Ally

  • New Member
  • *
  • Posts: 11
Re: TEdit with "FloatOnly"?
« Reply #20 on: August 07, 2020, 04:06:18 pm »
Hello Zoran,

Thank you for your reference to clocale.
I built it into my component and it works fine on Linux Mint.

Here is the revised version.

Greetings Roland

wp

  • Hero Member
  • *****
  • Posts: 7536
Re: TEdit with "FloatOnly"?
« Reply #21 on: August 07, 2020, 04:24:25 pm »
Hmmm... I know I did it also in fpspreadsheet as well. But the problem is that once a unit has been added to "uses" it cannot be removed any more. So, when you add clocale to your package it will be in all applications built with your package. What if somebody does not need what clocale provides and does not want it? He only can modify the package sources (which is never good) or he can stop using your package (which is not good either).

I think it is the more versatile option to remove clocale from your package and to write a big note in the readme.txt or the docs of your application that a Linux/Unix user of your component should add clocale to his project's uses clause somewhere if he needs locale information.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Ally

  • New Member
  • *
  • Posts: 11
Re: TEdit with "FloatOnly"?
« Reply #22 on: August 08, 2020, 05:13:10 pm »
Hello wp,

I changed it the way you suggested.
Readme.txt describes what you should pay attention to.

Greetings Roland

 

TinyPortal © 2005-2018