Sign in Join
Wiki copytemporary

Revision 2 of 2, by WikiArchive on 11-10-2026. The page as it is now.

TRadioButton

Comparison of several TRadioButton and a TRadioGroup with the characteristical properties given in the infobox.

TRadioButton tradiobutton.png provides an option to select "one-of-many" in a mutually exclusive way - if one RadioButton is selected, all others in the group are automatically deselected. The state of the Checked property is managed automatically among all RadioButtons belonging to the same parent component (there is no ButtonGroup property that needs to be set manually).

TRadioButtons are offered in the Standard tab of the Component Palette. To use a TRadioButton on a Form, you can simply select it on the component palette and place it, with one click on the form.

It usually does not make sense to use a single radiobutton, because radiobuttons are intended to provide several options to chose from. Instead of individual radiobuttons you can also use a TRadioGroup or other elements like a TComboBox to let the user select an option from a list.

In your source code, you can get the status of the radiobuttons, whether active or inactive, by using the Checked property. This is of the type Boolean, thus the querying and the assignment of Boolean values are both possible.

pascal
// Assignment: 
      RadioButton1.checked := true;
    
      // Query:
      var x: Boolean;
      x := RadioButton1.checked;
    
      // Conditional Check:
      if RadioButton1.checked then
      begin
          ...
      end;

Examples

Using an OnPaint event handler

pascal
procedure TForm1.btnPaintClick(Sender: TObject);
    begin
      if rbRed.Checked   then Color:=clRed;
      if rbGreen.Checked then Color:=clLime;
      if rbBlue.Checked  then Color:=clBlue;
    end;

RadioButtonExample1.png -> RadioButtonExample2.png

Using an OnChange event handler

The difference to the previous example is, we repaint the form not by a button click, but already by clicking one of the radio buttons themselves.

You can modify the previous example, by deleting the button and its OnClick event handler in the source code. You can create a new example but also easy:

pascal
procedure TForm1.rbRedChange(Sender: TObject);
    begin
      Self.Color:=clRed;    //with "Self", you select the object in which the method exists (method: rbRedChange / object: Form1)
    end;
    
    procedure TForm1.rbGreenChange(Sender: TObject);
    begin
      Form1.Color:=clLime;  //You can directly select the object ''Form1'', but poor, 
                            //because then no other object of class 'TForm1' can be created
    end;
    
    procedure TForm1.rbBlueChange(Sender: TObject);
    begin
      Color:=clBlue;        //or you leave out "Self" and the compiler will automatically detect its own object
    end;

RadioButtonExample3.png -> RadioButtonExample4.png

Grouping

If you add a radiobutton to your form it is added to a parent control (normally the TForm or a TPanel) which also determines their group a TRadioButton belongs to. With each change of the state of one of the radio buttons in the group (no matter whether via code or user clicking on it) it is automatically checked whether a different radiobutton is already Checked and if yes, the property Checked of this would be changed to False.

If you need to have multiple selections by RadioButtons on your form, which are meant to provide different, independent choices, you must group the radio buttons by placing them into a common parent container component like a TGroupBox or a TPanel for example (there are many others like a TPageControl, TNotebook, TScrollBox that are capable of providing a container for child elements). There is also a TRadioGroup component which provides a combination of grouping and layouting several radio buttons together.

Example

The following example shows how you can group radio buttons:

You can change the example A simple example or create a new application:

pascal
procedure TForm1.btnPaintClick(Sender: TObject);
    begin
      if rbRed.Checked   then Color:=Brightness or clRed;
      if rbGreen.Checked then Color:=Brightness or clLime;
      if rbBlue.Checked  then Color:=Brightness or clBlue;  
    end;
pascal
function TForm1.Brightness: TColor;
    begin
      Result:=0;
      if rbBrightMedDark.Checked then Result:=$888888;
      if rbBrightBright.Checked  then Result:=$DDDDDD;
    end;

RadioButtonExample5.png -> RadioButtonExample6.png

See also

LCL Components

Component Tab Components
Standard TMainMenu • TPopupMenu • TButton • TLabel • TEdit • TMemo • TToggleBox • TCheckBox • TRadioButton • TListBox • TComboBox • TScrollBar • TGroupBox • TRadioGroup • TCheckGroup • TPanel • TFrame • TActionList
Additional TBitBtn • TSpeedButton • TStaticText • TImage • TShape • TBevel • TPaintBox • TNotebook • TLabeledEdit • TSplitter • TTrayIcon • TControlBar • TFlowPanel • TMaskEdit • TCheckListBox • TScrollBox • TApplicationProperties • TStringGrid • TDrawGrid • TPairSplitter • TColorBox • TColorListBox • TValueListEditor
Common Controls TTrackBar • TProgressBar • TTreeView • TListView • TStatusBar • TToolBar • TCoolBar • TUpDown • TPageControl • TTabControl • THeaderControl • TImageList • TPopupNotifier • TDateTimePicker
Dialogs TOpenDialog • TSaveDialog • TSelectDirectoryDialog • TColorDialog • TFontDialog • TFindDialog • TReplaceDialog • TTaskDialog • TOpenPictureDialog • TSavePictureDialog • TCalendarDialog • TCalculatorDialog • TPrinterSetupDialog • TPrintDialog • TPageSetupDialog
Data Controls TDBNavigator • TDBText • TDBEdit • TDBMemo • TDBImage • TDBListBox • TDBLookupListBox • TDBComboBox • TDBLookupComboBox • TDBCheckBox • TDBRadioGroup • TDBCalendar • TDBGroupBox • TDBGrid • TDBDateTimePicker
Data Access TDataSource • TCSVDataSet • TSdfDataSet • TBufDataset • TFixedFormatDataSet • TDbf • TMemDataset
System TTimer • TIdleTimer • TLazComponentQueue • THTMLHelpDatabase • THTMLBrowserHelpViewer • TAsyncProcess • TProcessUTF8 • TProcess • TSimpleIPCClient • TSimpleIPCServer • TXMLConfig • TEventLog • TServiceManager • TCHMHelpDatabase • TLHelpConnector
Misc TColorButton • TSpinEdit • TFloatSpinEdit • TArrow • TCalendar • TEditButton • TFileNameEdit • TDirectoryEdit • TDateEdit • TTimeEdit • TCalcEdit • TFileListBox • TFilterComboBox • TComboBoxEx • TCheckComboBox • TButtonPanel • TShellTreeView • TShellListView • TXMLPropStorage • TINIPropStorage • TJSONPropStorage • TIDEDialogLayoutStorage • TMRUManager • TStrHolder
LazControls TCheckBoxThemed • TDividerBevel • TExtendedNotebook • TListFilterEdit • TListViewFilterEdit • TLvlGraphControl • TShortPathEdit • TSpinEditEx • TFloatSpinEditEx • TTreeFilterEdit • TExtendedTabControl •
RTTI TTIEdit • TTIComboBox • TTIButton • TTICheckBox • TTILabel • TTIGroupBox • TTIRadioGroup • TTICheckGroup • TTICheckListBox • TTIListBox • TTIMemo • TTICalendar • TTIImage • TTIFloatSpinEdit • TTISpinEdit • TTITrackBar • TTIProgressBar • TTIMaskEdit • TTIColorButton • TMultiPropertyLink • TTIPropertyGrid • TTIGrid
SQLdb TSQLQuery • TSQLTransaction • TSQLScript • TSQLConnector • TMSSQLConnection • TSybaseConnection • TPQConnection • TPQTEventMonitor • TOracleConnection • TODBCConnection • TMySQL40Connection • TMySQL41Connection • TMySQL50Connection • TMySQL51Connection • TMySQL55Connection • TMySQL56Connection • TMySQL57Connection • TSQLite3Connection • TIBConnection • TFBAdmin • TFBEventMonitor • TSQLDBLibraryLoader
Pascal Script TPSScript • TPSScriptDebugger • TPSDllPlugin • TPSImport Classes • TPSImport DateUtils • TPSImport ComObj • TPSImport DB • TPSImport Forms • TPSImport Controls • TPSImport StdCtrls • TPSCustomPlugin
SynEdit TSynEdit • TSynCompletion • TSynAutoComplete • TSynMacroRecorder • TSynExporterHTML • TSynPluginSyncroEdit • TSynPasSyn • TSynFreePascalSyn • TSynCppSyn • TSynJavaSyn • TSynPerlSyn • TSynHTMLSyn • TSynXMLSyn • TSynLFMSyn • TSynDiffSyn • TSynUNIXShellScriptSyn • TSynCssSyn • TSynPHPSyn • TSynTeXSyn • TSynSQLSyn • TSynPythonSyn • TSynVBSyn • TSynAnySyn • TSynMultiSyn • TSynBatSyn • TSynIniSyn • TSynPoSyn
Chart TChart • TListChartSource • TRandomChartSource • TUserDefinedChartSource • TCalculatedChartSource • TDbChartSource • TChartToolset • TChartAxisTransformations • TChartStyles • TChartLegendPanel • TChartNavScrollBar • TChartNavPanel • TIntervalChartSource • TDateTimeIntervalChartSource • TChartListBox • TChartExtentLink • TChartImageList
IPro TIpFileDataProvider • TIpHtmlDataProvider • TIpHttpDataProvider • TIpHtmlPanel
Virtual Controls TVirtualDrawTree • TVirtualStringTree • TVTHeaderPopupMenu

From the Free Pascal wiki, page "TRadioButton", as the Internet Archive kept it on 2025-01-21, last changed on 2024-11-22. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.