Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-09

Problem with ComboBox

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

faber

I've strange issue with that code:

  ComboBox1.ReadOnly:=true;
  ComboBox1.Items.Add('11.2');
  ComboBox1.Items.Add('11');
  ComboBox1.Items.Add('92');
  ComboBox1.Text:='11';

I always see 11.2 in ComboBox. This is a bug or I'm doing something wrong ? I use lazarus from svn and Win32.

best regards
faber

Reply by email

ik
to faber

Try to do something like

ComboBox1.ItemIndex := 1;

Ido

faber wrote 20 lines
I've strange issue with that code: ComboBox1.ReadOnly:=true; ComboBox1.Items.Add('11.2'); ComboBox1.Items.Add('11'); ComboBox1.Items.Add('92'); ComboBox1.Text:='11'; I always see 11.2 in ComboBox. This is a bug or I'm doing something wrong ? I use lazarus from svn and Win32. best regards faber -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100901/20526427/attachment.html>

Reply by email

faber
to ik

2010/9/1 ik :

Try to do something like ComboBox1.ItemIndex := 1;
Yes, in my case I must use loop:
        for i:=0 to ComBoBox1.Items.Count-1 do
           if faVar = strtofloat(ComboBox1.Items[i]) then begin
              ComboBox1.ItemIndex:=i;
              break;
           end;

however ComboBox.Text:='11' should work if '11' is in ComboBox1.Items, when I replace '11.2' with '22' then it works,
obviously the problem is with a decimal separator, so I thought it's a bug.

best regards
faber

Reply by email

John vd Waeter
to faber

It is a string, so decimal separator is not involved. I think setting the text likely invokes textsearch, like when typing, and then the first occurance matching '11' is '11.2'.

See what happens if you place '11' before '11.2'

john

faber wrote 26 lines
2010/9/1 ik : > Try to do something like > > ComboBox1.ItemIndex := 1; > Yes, in my case I must use loop: for i:=0 to ComBoBox1.Items.Count-1 do if faVar = strtofloat(ComboBox1.Items[i]) then begin ComboBox1.ItemIndex:=i; break; end; however ComboBox.Text:='11' should work if '11' is in ComboBox1.Items, when I replace '11.2' with '22' then it works, obviously the problem is with a decimal separator, so I thought it's a bug. best regards faber -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
John vd Waeter www.jvdw.nl www.gps-carpool.net www.shotinthedark.nl www.pdaforms.nl www.dbapocket.nl

Reply by email

faber
to John vd Waeter

2010/9/1 John vd Waeter :

Show quoted text 6 lines
It is a string, so decimal separator is not involved. I think setting the text likely invokes textsearch, like when typing, and then the first occurance matching '11' is '11.2'. See what happens if you place '11' before '11.2'

;) nice

result of that code in ComboBox is '112'

 ComboBox1.ReadOnly:=true;
 ComboBox1.Items.Add('112');
 ComboBox1.Items.Add('11');
 ComboBox1.Items.Add('92');
 ComboBox1.Text:='11';

best regards
faber

Reply by email

John vd Waeter
to faber
Show quoted text 14 lines
;) nice result of that code in ComboBox is '112' ComboBox1.ReadOnly:=true; ComboBox1.Items.Add('112'); ComboBox1.Items.Add('11'); ComboBox1.Items.Add('92'); ComboBox1.Text:='11'; best regards faber

I meant:

Show quoted text 6 lines
ComboBox1.ReadOnly:=true; ComboBox1.Items.Add('10'); ComboBox1.Items.Add('11'); ComboBox1.Items.Add('11.2'); ComboBox1.Items.Add('92'); ComboBox1.Text:='11';

Now they are in *alphabetical* order.
;-)
John

Reply by email

Paul Parkyn
to John vd Waeter: It is a string, so decimal separator is not involved. I think setting the text likely…
John vd Waeter wrote 31 lines
It is a string, so decimal separator is not involved. I think setting the text likely invokes textsearch, like when typing, and then the first occurance matching '11' is '11.2'. See what happens if you place '11' before '11.2' john faber wrote: > 2010/9/1 ik : >> Try to do something like >> >> ComboBox1.ItemIndex := 1; >> > > Yes, in my case I must use loop: > for i:=0 to ComBoBox1.Items.Count-1 do > if faVar = strtofloat(ComboBox1.Items[i]) then begin > ComboBox1.ItemIndex:=i; > break; > end; > > however ComboBox.Text:='11' should work if '11' is in ComboBox1.Items, > when I replace '11.2' with '22' then it works, > obviously the problem is with a decimal separator, so I thought it's a bug. > > best regards > faber > > --

have you tried something like this:-

     If ComboBox1.Items.IndexOf(FloatToStr(faVar))  -1 then
     begin
       ComboBox1.ItemIndex:=ComboBox1.Items.IndexOf(FloatToStr(faVar));
       Label1.Caption:=Msg + IntToStr(ComboBox1.ItemIndex);
     end;

Reply by email