Delphi get android combobox selected item text

Alberto Rossi picture Alberto Rossi · Sep 24, 2013 · Viewed 12.3k times · Source

I have a combobox that has a lot of items inside and I have to get into a variable the name of the selected item.

var a:string;
begin
 a:=ComboBox1.Text;
end;

This is the way I used for a Delphi VCL application and it works. Here I'm developing with Firemonkey and Android, I haven't the text property.

How can I get the text of the selected item on my combobox?

Answer

Ken White picture Ken White · Sep 25, 2013

The same way works in FireMonkey as in VCL code - use the TComboBox.Items. TComboBox.ItemIndex tells you which one is currently selected (or allows you to set the selection).

To read:

if ComboBox1.ItemIndex <> -1 then
  ShowMessage(ComboBox1.Items[ComboBox1.ItemIndex]);

To set:

ComboBox1.ItemIndex := 2;