Search code examples
delphipointerscomboboxvcl

Dephi: Passing a data pointer to a comboboxitem


I want to bind a object to an Item. I allready saw this functionality in TListView, but I couldn't find it in TComboBox. Is there a way to bind an object to a comboBoxItem in delphi? Note that I'm using vcl.


Solution

  • Use AddObject method of combobox Items property.

    var
      pt : Pointer;
    begin
    //...
      myCombobox.Items.AddObject('Some string', pt);
    

    Be aware however, that using this method to store interface pointers is unsafe because it ignores reference counting.