Radio Group Guide
TTMSFNCRadioGroup renders a bordered group box containing a set of radio buttons from its Items collection. TTMSFNCRadioGroupPicker embeds the same group inside a dropdown popup, useful where screen space is limited. Both controls support HTML-formatted item text and anchor click events.
Adding items and reading the selection
Populate the Items collection and set ItemIndex to preselect an option. The OnRadioButtonClick event returns the index of the clicked item.
// Add items and select the first one
TMSFNCRadioGroup1.Items.Add('Option A');
TMSFNCRadioGroup1.Items.Add('Option B');
TMSFNCRadioGroup1.Items.Add('Option C');
TMSFNCRadioGroup1.ItemIndex := 0;
// React to a selection
procedure TForm1.TMSFNCRadioGroup1RadioButtonClick(Sender: TObject; AItemIndex: Integer);
begin
Label1.Caption := 'Selected index: ' + IntToStr(AItemIndex);
end;
Multi-column layout and title checkbox
Use the Columns property to flow items into multiple columns. The Title sub-object exposes a ShowCheckBox option that places a checkbox in the title bar; setting CheckBoxMode to rgtcmToggleEnabled automatically enables or disables all radio buttons when the checkbox changes.
// Arrange items in two columns
TMSFNCRadioGroup1.Items.Add('Red');
TMSFNCRadioGroup1.Items.Add('Green');
TMSFNCRadioGroup1.Items.Add('Blue');
TMSFNCRadioGroup1.Items.Add('Yellow');
TMSFNCRadioGroup1.Columns := 2;
TMSFNCRadioGroup1.ItemIndex := 0;
// Title with optional checkbox that enables/disables the group
TMSFNCRadioGroup1.Title.Caption := 'Pick a color';
TMSFNCRadioGroup1.Title.ShowCheckBox := True;
TMSFNCRadioGroup1.Title.CheckBoxMode := rgtcmToggleEnabled;
This pattern is useful for optional sections in settings dialogs where the entire group can be toggled off.
Using TTMSFNCRadioGroupPicker with HTML and anchors
TTMSFNCRadioGroupPicker shows the radio group in a dropdown that opens when the control is clicked. HTML markup in items and OnRadioButtonAnchorClick let you embed hyperlinks inside individual option labels.
// TTMSFNCRadioGroupPicker drops down a radio group in a popup
TMSFNCRadioGroupPicker1.Items.Add('Small');
TMSFNCRadioGroupPicker1.Items.Add('Medium');
TMSFNCRadioGroupPicker1.Items.Add('Large');
TMSFNCRadioGroupPicker1.ItemIndex := 1;
// Combine HTML items with column layout and anchor click handling
TMSFNCRadioGroupPicker1.Items.Clear;
TMSFNCRadioGroupPicker1.Items.Add('<b>Economy</b> – standard delivery');
TMSFNCRadioGroupPicker1.Items.Add('<b>Express</b> – <a href="info">more info</a>');
TMSFNCRadioGroupPicker1.Columns := 1;
procedure TForm1.RadioGroupPickerRadioButtonAnchorClick(Sender: TObject;
AItemIndex: Integer; AAnchor: string);
begin
if AAnchor = 'info' then
ShowMessage('Express delivers within 24 hours.');
end;
Combining the picker with HTML items and anchor events covers the common use case of options that need an inline help link without a separate label.
Events
Beyond OnRadioButtonClick, TTMSFNCRadioGroup exposes three more events for finer-grained interaction. Reach for these when a single click on an item is not enough context, or when the title or item text carries its own embedded link:
OnRadioButtonDblClickfires when a radio button item is double-clicked, useful for a "confirm and continue" shortcut that skips an explicit OK button.OnTitleAnchorClickfires when an<a href>anchor inside the group's HTML title is clicked, for example a "what's this?" help link next to the group heading.OnRadioButtonAnchorClickfires when an<a href>anchor inside an individual item's HTML text is clicked, letting each option carry its own inline details link separate from selecting that option.
All three events pass enough context to distinguish which control raised them: the click events report the zero-based item index, and the anchor events additionally report the clicked anchor's href value.
procedure TForm1.FormCreate(Sender: TObject);
begin
// HTML title with an inline anchor
TMSFNCRadioGroup1.Title.Text := 'Choose a plan (<a href="help">what''s this?</a>)';
// HTML item text with its own inline anchor
TMSFNCRadioGroup1.Items.Add('<b>Basic</b> – <a href="basic-info">details</a>');
TMSFNCRadioGroup1.Items.Add('<b>Pro</b> – <a href="pro-info">details</a>');
TMSFNCRadioGroup1.ItemIndex := 0;
TMSFNCRadioGroup1.OnRadioButtonDblClick := DoRadioButtonDblClick;
TMSFNCRadioGroup1.OnTitleAnchorClick := DoTitleAnchorClick;
TMSFNCRadioGroup1.OnRadioButtonAnchorClick := DoRadioButtonAnchorClick;
end;
// Fires when a radio button item is double-clicked; AItemIndex is the
// zero-based index of the item that was double-clicked.
procedure TForm1.DoRadioButtonDblClick(Sender: TObject; AItemIndex: Integer);
begin
StatusBar1.Panels[0].Text := 'Double-clicked option ' + IntToStr(AItemIndex + 1);
end;
// Fires when the reader clicks an <a href> anchor inside the group title.
// AAnchor carries the href value so you can route to the right help topic.
procedure TForm1.DoTitleAnchorClick(Sender: TObject; AAnchor: string);
begin
if AAnchor = 'help' then
ShowMessage('Plans are billed monthly and can be changed at any time.');
end;
// Fires when the reader clicks an <a href> anchor inside an individual radio
// button item's text. AItemIndex identifies which item owns the anchor and
// AAnchor carries the href value.
procedure TForm1.DoRadioButtonAnchorClick(Sender: TObject; AItemIndex: Integer;
AAnchor: string);
begin
if AAnchor = 'basic-info' then
ShowMessage('Basic: 1 user, community support.')
else if AAnchor = 'pro-info' then
ShowMessage('Pro: unlimited users, priority support.');
end;
Combining items, multi-column layout, and the picker dropdown
Populate a two-column group, wire the click event, and also expose the same items in a compact picker control:
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
begin
// Shared items for both controls
for I := 1 to 6 do
begin
TMSFNCRadioGroup1.Items.Add('Option ' + IntToStr(I));
TMSFNCRadioGroupPicker1.Items.Add('Option ' + IntToStr(I));
end;
// Two-column layout with a toggleable title checkbox
TMSFNCRadioGroup1.Columns := 2;
TMSFNCRadioGroup1.Title.Text := 'Choose one';
TMSFNCRadioGroup1.Title.ShowCheckBox := True;
TMSFNCRadioGroup1.Title.CheckBoxMode := rgtcmToggleEnabled;
TMSFNCRadioGroup1.ItemIndex := 0;
TMSFNCRadioGroup1.OnRadioButtonClick := DoRadioClick;
// Picker shows the same items in a dropdown
TMSFNCRadioGroupPicker1.ItemIndex := 0;
end;
procedure TForm1.DoRadioClick(Sender: TObject; AItemIndex: Integer);
begin
StatusBar1.Panels[0].Text := 'Selected: Option ' + IntToStr(AItemIndex + 1);
end;