7

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?

Alberto Rossi
  • 1,800
  • 4
  • 36
  • 58

2 Answers2

8

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;
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • 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. – Rob Kennedy Sep 24 '13 at 22:54
8

you can access the Selected property to get text :

 if ComboBox1.ItemIndex >= 0 then
    ShowMessage(ComboBox1.Selected.Text);
S.MAHDI
  • 1,022
  • 8
  • 15