Make a form with 1 combobox and three buttons and wire the procedures below in and you will get the point (notice that you will have to use QWord instead of Integer if you use literals like I did in my example):
procedure TForm1.button_LoadClick(Sender: TObject);
begin
combobox.AddItem('Chevrolet', TObject(17));
combobox.AddItem('Nissan', TObject(22));
combobox.AddItem('Ford', TObject(13));
combobox.AddItem('Toyota', TObject(42));
combobox.AddItem('VW', TObject(56));
//
combobox.ItemIndex := 0;
button_Key.Enabled := True;
button_String.Enabled := True;
end;
procedure TForm1.button_StringClick(Sender: TObject);
var
index: Integer;
begin
// get the 'key' for the string 'Toyota' (if present in combobox)
index := combobox.Items.IndexOf('Toyota');
if (index <> -1) then
ShowMessage('Key for Toyota: ' + IntToStr(QWord(combobox.Items.Objects[index])))
else
ShowMessage('String ' + QuotedStr('Toyota') + ' not found.');
end;
procedure TForm1.button_KeyClick(Sender: TObject);
var
index: Integer;
begin
// see if we have a string in the combobox for key #13
index := combobox.Items.IndexOfObject(TObject(13));
if (index <> -1) then
ShowMessage('String for Key #13: ' + combobox.Items[index])
else
ShowMessage('Key #13 not found.');
end;