How do i assign a RadioButton to a RadioGroup in XE2?

delphi, delphi-xe2, radio-button

Solution

You cannot manually add a TRadioButton to a TRadioGroup. The TRadioGroup control has always worked in this way. You must use its `Items` property to add the radio buttons.

The Embarcadero documentation says

To add radio buttons to a TRadioGroup, edit the Items property in the Object Inspector. Each string in Items makes a radio button appear in the group box with the string as its caption. The value of the ItemIndex property determines which radio button is currently selected.

So you can use the Object Inspector to edit the `Items` property or writing code like this:

RadioGroup1.Items.Add('Option 1');
RadioGroup1.Items.Add('Option 2');
RadioGroup1.Items.Add('Option 3');
RadioGroup1.Items.Add('Option 4');
RadioGroup1.Items.Add('Option 5');

Finally to check which radio button is selected use the `ItemIndex` property like so

if RadioGroup1.ItemIndex>=0 then
  ShowMessage(RadioGroup1.Items[RadioGroup1.ItemIndex]);

Problem

Don't hate (or devote) me on this silly question, but i noticed on XE2 it has changed, i try to drop a new RadioButton to a RadioGroup and i notice it is actually NOT a part of that group, why ? and what is this TStrings i need to write ? it's kind of hard for me to control it like that.

Original source