Recent

Author Topic: How do I convert a control to ComboBox?  (Read 1462 times)

nikel

  • Sr. Member
  • ****
  • Posts: 282
How do I convert a control to ComboBox?
« on: November 29, 2018, 01:50:05 pm »
Hi, I created a record and want to assign a combobox to it. Here's my code:

Code: Pascal  [Select][+][-]
  1. type
  2.   TControlData = record
  3.     Control  : TControl;
  4.     Value    : String;
  5. end;
  6.  
  7. ...
  8.  
  9. if (TxtDataTypeTitle = 'Boolean') then
  10. begin
  11.   ControlData.Control:=Value_Cmbx;
  12.   ControlData.Control.Items.Clear;
  13.   ControlData.Control.Items.Add('True');
  14.   ControlData.Control.Items.Add('False');
  15. end;
  16.  

I'm getting error: unit1.pas(547,25) Error: identifier idents no member "Items"

balazsszekely

  • Guest
Re: How do I convert a control to ComboBox?
« Reply #1 on: November 29, 2018, 01:57:27 pm »
You have to do a typecast first:
Code: Pascal  [Select][+][-]
  1.  TComboBox(ControlData.Control).Items.Clear;
  2.  TComboBox(ControlData.Control).Items.Add('True');
  3.  TComboBox(ControlData.Control).Items.Add('False');

Even better, you should check if the control is a TComboBox. This is especially important if you're using more then one type.
Code: Pascal  [Select][+][-]
  1. if (ControlData.Control is TComboBox) then
  2. begin
  3.   (ControlData.Control as TComboBox).Items.Clear;
  4.   //...
  5. end;
« Last Edit: November 29, 2018, 02:14:06 pm by GetMem »

nikel

  • Sr. Member
  • ****
  • Posts: 282
Re: How do I convert a control to ComboBox?
« Reply #2 on: November 29, 2018, 02:57:01 pm »
That helped a lot thanks for the reply.

 

TinyPortal © 2005-2018