Link to home
Start Free TrialLog in
Avatar of pg6111
pg6111

asked on

How do I retrieve text from an item displayed in a ComboBox?

I am using Delphi 10.3, and need to retrieve the Text from a ComboBox.  The ComboBox was loaded earlier via:

        for PLCIndex := 0 to numDoorPLCs - 1 do
           begin
               if (tmpDoorMng.returnDoorPLCController(tmpDoorPLC,PLCIndex)) then
               begin
                   plc_name := tmpDoorPLC.get_Comm.get_name;
                   cbDoorPLC.Items.Add(plc_name);
               end;
           end;

When the user later selects an item from the ComboBox, I need to get the text for that item.  How is it done?
Avatar of Jonathan D.
Jonathan D.
Flag of Israel image

You get the index of the current selected item and then access it through Items property.

If you're adding plain primitive types then just cast to the data type, but if it's a data structure you'd have to cast to the data structure type.
Avatar of pg6111
pg6111

ASKER

I am using primitive types and am trying to retrieve data from the ComboBox after loading it earlier in the program.  

SelectedPLCStr is defined as a String.
I tried the following two statements, and neither one worked.  
         SelectedPLCStr := cbDoorPLC.GetItemIndex.Text;
         SelectedPLCStr := cbDoorPLC.ItemIndex.Text;
 
ASKER CERTIFIED SOLUTION
Avatar of Jonathan D.
Jonathan D.
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pg6111

ASKER

Yes, that did the trick!  Thank you so much!!!