Recent

Author Topic: TUpDown inserts separator  (Read 4190 times)

hy

  • Full Member
  • ***
  • Posts: 221
TUpDown inserts separator
« on: October 21, 2014, 07:08:29 pm »
I am having a tUpDown control on a form and a TEdit is associated.
The TEdit contains year-numbers.
When clicking the TUpDown the number is incremented/decremented but a thousand-separator is inserted.
the TEdit shows: "2,014" instead of "2014"
How can I get rid of that? Thanks in advance
_____
***hy
OS: debian sid(64bit)  [fpc 3.20] Lazarus 2.0.12

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: TUpDown inserts separator
« Reply #1 on: October 21, 2014, 09:03:03 pm »
How do you apply changes to TEdit text ?

hy

  • Full Member
  • ***
  • Posts: 221
Re: TUpDown inserts separator
« Reply #2 on: October 21, 2014, 11:13:53 pm »
I am taking
var s:string
begin
     s:=editYear.text

and there is the separator.

My solution is:
Code: [Select]
   {$ifdef Lazarus}
      lReset := false;
      s := '';
      sTmp := eJahr.Text;
      iMax := length(sTmp);
      for i := 1 to iMax do
      begin
         if sTmp[i] in [#48..#57] then
            s := s + sTmp[i]
         else
            lReset := true;
      end;
      if lReset then
         eJahr.Text := s;
   {$Else}
      s := eJahr.Text;
   {$Endif}
   i_Year := eval2IntDef(s, -4001);
   if i_Year > -4001 then
      yCal.iYear := i_Year;
   

eval2Intdef (x) evaluates on the current locale settings - thus interpreting '.' as a thousand separator and ',' as a decimal separator. But the problem is that I get ',' as thousand separators and I actually have '.' dots as separators.
_____
***hy
OS: debian sid(64bit)  [fpc 3.20] Lazarus 2.0.12

sam707

  • Guest
Re: TUpDown inserts separator
« Reply #3 on: October 22, 2014, 12:32:34 am »
I just put a TEdit component on a form and in the OnCreate event I set it with 2014 this way

  Edit1.Text:=IntToStr(2014);

then I run the program, there is no coma ',' nor point '.' displayed at all, just '2014'

if I then want the value back, I write

  value:=StrToInt(Edit1.Text);

assuming value is an integer variable

to see thousands separators and dots, I guess, there are "Float" functions somewhere in use that are useless for a year assignment

http://www.freepascal.org/docs-html/rtl/sysutils/inttostr.html
http://www.freepascal.org/docs-html/rtl/sysutils/strtoint.html

furthermore, TUpdown component internally uses smallint datatype (-32768 to +32767)
« Last Edit: October 22, 2014, 12:50:23 am by sam707 »

sam707

  • Guest
Re: TUpDown inserts separator
« Reply #4 on: October 22, 2014, 12:59:21 am »
oh wait a minute, seems there is a bug in automated TUpdown changes

I give you a solution to bypass that bug... wich dislplayed '2?015' to me when i pressed on the up arrow of the TUpdown

here is the rough trick =

Code: [Select]
procedure TForm1.Edit1Change(Sender: TObject);
begin
  Edit1.Text:=IntToStr(UpDown1.Position);
end;

set the OnChange event of your TEdit to the above procedure and all will be fine at display!

explaination =

TUpdown event when clicked, internally changes the contents of its associated control... after what, I catch the event of the just changed control

  Edit1.OnChange := @Edit1Change; // From TForm1

and I correct the display. Okay it is not fair, because the display is modified twice (thats why i call it 'rough' trick) but it works and your eyes arent fast enough to see the flicker ;)
« Last Edit: October 22, 2014, 09:01:06 am by sam707 »

hy

  • Full Member
  • ***
  • Posts: 221
Re: TUpDown inserts separator
« Reply #5 on: October 22, 2014, 12:47:09 pm »
Ok I got it. There is in fact a property  named "thousands" that is set to TRUE by default.
I have overseen it up to now.
_____
***hy
OS: debian sid(64bit)  [fpc 3.20] Lazarus 2.0.12

sam707

  • Guest
Re: TUpDown inserts separator
« Reply #6 on: October 22, 2014, 06:45:13 pm »
saw it too thx. and yup, better to set it to false by Default, the thousands separator is bug in my locale at least .... displays a '?'  should be  a ' '. so if i want a thousand representation someday, i use my trick and instert manually a space in the Text
« Last Edit: October 22, 2014, 09:40:58 pm by sam707 »

 

TinyPortal © 2005-2018