I have a form containing a combobox and a label and
the following code:
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
iname: integer=0;
begin
ComboBox1.Clear;
for i:=0 to 50 do
begin
iname:=iname+ 1+ trunc(Random*
;
ComboBox1.Items.Add(IntToStr(iname) + '(' + IntToStr(i) + ')');
end; //for
ComboBox1.ItemIndex:=0;
ComboBox1.AutoComplete:=True;
ComboBox1.AutoCompleteText:=[cbactEnabled,cbactSearchAscending];
ComboBox1.AutoDropDown:=True;
end;
procedure TForm1.ComboBox1EditingDone(Sender: TObject);
begin
Label1.Caption:=IntToStr(ComboBox1.ItemIndex);
end;
When I execute the code, I start typing in the combobox for example 145.
If there is a value „145(35)‟ in the combobox I expect that when I hit Enter I will get Label1 showing „35‟, because the itemindex of entry „145(35)‟ is 35.
And that is what I get if ComboBox1.AutoDropDown:=False;
But when ComboBox1.AutoDropDown:=True; instead of 145, I get for example 0, because the first entry in the combo, starting with 1 has ItemIndex=0.
Or if there is a value „217(43)‟ in the combobox I expect that when I hit enter I will get Label1 showing „43‟. But it shows something like „2‟, because the first entry starting with „2‟ is „2‟ or „25‟ or something like this.
Again, if ComboBox1.AutoDropDown:=False; I get 43 (as expected), since the ItemIndex of entry „217(43)‟ is 43.
Is this some bug in Lazarus, and if not, is there a way to overcome this behaviour?