Kanat Posted April 6, 2015 Posted April 6, 2015 Hi guys! Create 3 items. UniComboBox1.Items.AddObject('111', TObject(1)); UniComboBox1.Items.AddObject('111', TObject(2)); UniComboBox1.Items.AddObject('112', TObject(3)); Example UniComboBox1.ItemIndex:=0; ShowMessage(IntToStr(Integer(UniComboBox1.Items.Objects[uniComboBox1.ItemIndex])); Result : 1 UniComboBox1.ItemIndex:=1; ShowMessage(IntToStr(Integer(UniComboBox1.Items.Objects[uniComboBox1.ItemIndex])); Result : 1 UniComboBox1.ItemIndex:=2; ShowMessage(IntToStr(Integer(UniComboBox1.Items.Objects[uniComboBox1.ItemIndex])); Result : 3 in the first and second case gets results : 1 Please help? Quote
Tim Posted April 6, 2015 Posted April 6, 2015 Hi Kanatshym, I assume you have valid reasons for wanting the first two items in the combobox to appear identical to the user. It does appear that TUniCombobox.ItemIndex malfunctions if two or more items have truly identical text. As a workaround, you might like to consider putting a space at the end of one of the items: UniComboBox1.Items.AddObject('111', TObject(1)); UniComboBox1.Items.AddObject('111 ', TObject(2)); UniComboBox1.Items.AddObject('112', TObject(3)); The user is unlikely to notice the difference, but this is sufficient (based on my tests) to get TUniCombobox.ItemIndex working again. I hope this helps Tim Quote
Kanat Posted April 6, 2015 Author Posted April 6, 2015 Hi Kanatshym, I assume you have valid reasons for wanting the first two items in the combobox to appear identical to the user. It does appear that TUniCombobox.ItemIndex malfunctions if two or more items have truly identical text. As a workaround, you might like to consider putting a space at the end of one of the items: UniComboBox1.Items.AddObject('111', TObject(1)); UniComboBox1.Items.AddObject('111 ', TObject(2)); UniComboBox1.Items.AddObject('112', TObject(3)); The user is unlikely to notice the difference, but this is sufficient (based on my tests) to get TUniCombobox.ItemIndex working again. I hope this helps Tim In my project there are duplicate rows, "VCL" everything works fine Quote
Tim Posted April 6, 2015 Posted April 6, 2015 Hi Kanatshym, I realise this is an inconsistency (or possibly a bug) between UniGui and the Delphi VCL. That is why i am suggesting a workaround. You might even consider writing a function to perform the workaround automatically, something like this: procedure TMainForm.UniFormCreate(Sender: TObject); function AddObjectToComboBox(AUniCombobox : TUniCombobox; AItem : string; AObject: TObject): Integer; var i : integer; begin while AUniCombobox.Items.IndexOf(AItem) <> -1 do begin AItem := AItem + ' '; end; result := AUniCombobox.Items.AddObject(AItem, AObject); end; begin AddObjectToComboBox(UniComboBox1, '111', TObject(1)); AddObjectToComboBox(UniComboBox1, '111', TObject(2)); AddObjectToComboBox(UniComboBox1, '112', TObject(3)); end; In the VCL version of your application you could then leave the first three lines of AddObjectToComboBox commented out. I hope this helps, Tim Quote
Kanat Posted April 6, 2015 Author Posted April 6, 2015 Hi Kanatshym, I realise this is an inconsistency (or possibly a bug) between UniGui and the Delphi VCL. That is why i am suggesting a workaround. You might even consider writing a function to perform the workaround automatically, something like this: procedure TMainForm.UniFormCreate(Sender: TObject); function AddObjectToComboBox(AUniCombobox : TUniCombobox; AItem : string; AObject: TObject): Integer; var i : integer; begin while AUniCombobox.Items.IndexOf(AItem) <> -1 do begin AItem := AItem + ' '; end; result := AUniCombobox.Items.AddObject(AItem, AObject); end; begin AddObjectToComboBox(UniComboBox1, '111', TObject(1)); AddObjectToComboBox(UniComboBox1, '111', TObject(2)); AddObjectToComboBox(UniComboBox1, '112', TObject(3)); end; In the VCL version of your application you could then leave the first three lines of AddObjectToComboBox commented out. I hope this helps, Tim Thanks, I already fixed, it took me a long time to find this error. I think Farhad fix in the next release. 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.