From Clomosy Docs
function AddNewRadioGroup(xOwner: TCLComponent; xName, xCaption: string): TclRadioGroup;
xOwner : Specifies the parent of the object to be defined.
xName : The name of the defined radio button should be written.
xCaption : You can add a title.
TclRadioButton, also known as an option button, presents a set of mutually exclusive choices. You can create individual radio buttons using TclRadioButton, or use a group structure to automatically organize the buttons. By grouping radio buttons, the user is allowed to select only one option from a limited set.
A selected radio button is displayed as a circle filled in the center. If not selected, only an empty circle is shown. To change the visual state of the radio button, you can assign the value True or False to the IsChecked property.
| Feature | Use of | Definition |
|---|---|---|
| TclRadioGroup | RadioGroup1 : TclRadioGroup; | A variable belonging to the TclRadioGroup class is created. |
| AddNewRadioGroup | RadioGroup1 = Form1.AddNewRadioGroup(Form1,'RadioGroup1','Test Radio Group Caption'); | A new TclRadioGroup is added to the form. |
| Title.Text | RadioGroup1.Title.Text = 'Select something...'; | Sets the title or prompt that appears above or within the RadioGroup, guiding the user on what to select. |
| Items.Add | RadioGroup1.Items.Add('Value1'); | The RadioGroup object can have items added to it. These items are the options that the user can choose from. |
| Items.Text | GroupValue = RadioGroup1.Items.Text; //GroupValue : String | It is a property that returns the combined text of all the component's items. It displays all the items as a single text, separating each item with a space. |
| Items.Clear | RadioGroup1.Items.Clear; | It deletes all the items (options) within the object. |
| Items | SelectedText = RadioGroup1.Items[3]; //SelectedText : String | Retrieves the text of the selected item (index). In the example, it accesses the data of the item at index 3. |
| ItemIndex | SelectedIndex = RadioGroup1.ItemIndex; //SelectedIndex : Integer | Holds the index of the currently selected radio button in the group. |
Example
The TclRadioGroup object created on the form is populated with data taken from an array. When the user selects one of the options, the index and value of the selected item are retrieved.
var
MainForm:TclForm;
GenderRadioGroup:TClRadioGroup;
OptionsArray: array[2] of string;
I : Integer;
void OnRadioButtonClick;
var
SelectedIndex: Integer;
SelectedText: String;
{
SelectedIndex = GenderRadioGroup.ItemIndex;
if (SelectedIndex >= 0)
{
SelectedText = GenderRadioGroup.Items[SelectedIndex];
ShowMessage('Selected: ' + SelectedText + ' (Index: ' + IntToStr(SelectedIndex) + ')');
}
}
{
OptionsArray = ['Female','Male','Prefer not to say'];
MainForm = TclForm.Create(Self);
GenderRadioGroup = MainForm.AddNewRadioGroup(MainForm,'GenderRadioGroup','----');
GenderRadioGroup.Align = alClient;
GenderRadioGroup.Title.Text = 'Select gender...';
for (I = 0 to High(OptionsArray))
GenderRadioGroup.Items.Add(OptionsArray[I]);
ShowMessage(GenderRadioGroup.Items.Text);
MainForm.AddNewEvent(GenderRadioGroup, tbeOnClick, 'OnRadioButtonClick');
MainForm.Run;
}
Output:
See Also
