Domanda

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?

È stato utile?

Soluzione

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;

Altri suggerimenti

you can access the Selected property to get text :

 if ComboBox1.ItemIndex >= 0 then
    ShowMessage(ComboBox1.Selected.Text);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top