Delphi get android combobox selected item text

13,518

Solution 1

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;

Solution 2

you can access the Selected property to get text :

 if ComboBox1.ItemIndex >= 0 then
    ShowMessage(ComboBox1.Selected.Text);
Share:
13,518
Alberto Rossi
Author by

Alberto Rossi

Updated on June 26, 2022

Comments

  • Alberto Rossi
    Alberto Rossi almost 2 years

    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?

  • Rob Kennedy
    Rob Kennedy over 10 years
    The code in the question hasn't necessarily been wrong in VCL applications. When Style is csSimple or csDropDown, what other way is there to determine the text when the text has been typed in and doesn't match any item in the list? FireMonkey lacks a Style property, and apparently lacks an editable combo box entirely.