The TRadioGroup component is a perfect replacement for a TGroupBox component that only contains TRadioButton components. The main difference between the TGroupBox and the TRadioGroup components is that the TRadioGroup component can't act as a container. The TRadioGroup component can only contain radio buttons defined in its Items property.
Figure 14-17: The TRadioGroup component
Normally, to see if a radio button is selected, you have to test its Checked property. Since the radio buttons in a TRadioGroup aren't real radio buttons, you cannot check the Checked property of a certain radio button. To determine which radio button is selected in a TRadioGroup component, use the ItemIndex property.
Listing 14-21: Using TRadioGroup radio buttons
procedure TForm1.Button1Click(Sender: TObject); begin if RadioGroup1.ItemIndex = -1 then begin MessageDlg('Select a radio button first.', mtWarning, [mbOK], 0); Exit; end; with TForm.Create(Self) do try BorderStyle := TFormBorderStyle(RadioGroup1.ItemIndex); Caption := RadioGroup1.Items[RadioGroup1.ItemIndex]; Position := poScreenCenter; ShowModal; finally Free; end; end;