Mirror

How to store two strings in the item of a TComboBox (Views: 100)


Problem/Question/Abstract:

I want to store a second string in a combobox item. How can I do this without defining an object wrapper?

Answer:

procedure AddString(const S1, S2: string; Items: TStrings);
var
  Obj: TObject;
begin
  Obj := nil;
  string(Obj) := S2;
  Items.AddObject(S1, Obj);
end;

procedure DeleteItem(const I: Integer; Items: TStrings);
var
  Obj: TObject;
begin
  Obj := Items.Objects[I];
  Items.Objects[I] := nil;
  string(Obj) := '';
end;


Just be sure to go over every item and release the string.

<< Back to main page