Hello Jesper,

Of course you can use the Objects property of the
ComboBox's Items property. Here is some code snippet
for populating the combobox and find the selected
object.

procedure PopulatingCombo(AComboBox: TComboBox; AList:
TList);
begin
  AComboBox.Clear;
  for i := 0 to AList.Count-1 do
   
AComboBox.Items.AddObject(TMyObject(AList[i]).Name,
TMyObject(AList[i]));
end;

procedure FormXXX.Combo1Click(Sender: TObject);
begin
  if Combo1.ItemIndex > -1 then
    MyActiveObject :=
TMyObject(Combo1.Items.Objects[Combo1.ItemIndex])
  else
    MyActiveObject := nil;
end;

Btw, if you want to know more about the Objects
property, you can read Delphi Help for TStrings class.
For Items property of TComboBox is aTStrings
descendant.

Regards,

Luthfi B Hakim

> Hi all.
> 
> I have a TList with a bunch of objects and I want to
> use a ComboBox to 
> display them and let the user select the object to
> work with.
> 
> Getting the information into the combo is of course
> no problem but what is 
> the smartest way to keep the connection between an
> item in the combo and 
> the object in the TList?
> If I have a TListView instead it's much easier. Just
> use the property 
> "Data" on the TListItem that is added and let it
> point to the object in 
> the TList.
> 
> Of course I can use the index of the selected item
> in the combo and then 
> pick out the item with the corresponding index in th
> TList, but what if 
> the combobox is sorted? 
> 
> Is there an easy, smart and nice way to do this?
> 
> //Jesper


      
____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 

_______________________________________________
Delphi mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

Reply via email to