Difference between revisions of "TRadioGroup"

From Free Pascal wiki
Jump to navigationJump to search
m
(→‎Small example: language)
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
>> [[LCL Components]] >> TRadioGroup<br/>
+
{{TRadioGroup}}
  
This page explains how to use the TRadioGroup component. When I mention to click on something, unless I explicitly say to right-click, you always left-click on the item in question.
+
A '''TRadioGroup''' [[image:tradiogroup.png]] is a group of related but mutually exclusive [[TRadioButton]]s, requiring the user to select one of a set of alternatives. It's like a [[TGroupBox]] with integrated [[TRadioButton|TRadioButtons]].
  
 +
==Usage==
 +
To use a TRadioGroup on a [[TForm|form]], you can simply select it on the [[Standard tab]] of the [[Component Palette]] and place it by clicking on the form.
  
 +
===Small example===
 +
Geometric figures should be drawn randomly and depending on the TRadioGroups to the form. The first RadioGroup determines the shape, the second RadioGroup detrmines the number.
 +
* create a new application and place two TRadioGroups on your form
 +
* change in the Object Inspector the [[Property|property]] ''Name'' of ''RadioGroup1'' to ''rgShape'', also ''RadioGroup2'' to ''rgCount''
 +
* change identical ''Caption'' of ''rgShape'' to ''Shape'' and that of ''rgCount'' to ''Count''
 +
* add the RadioButtons for ''rgShape'':
 +
** in the Object Inspector select the property ''Items'' of ''rgShape''
 +
** click on the button [...], the character chain editor opens
 +
** write among each other ''Lines Rectangles Ellipses'' and complete the entry with the button ''OK''
 +
* add identical the RadioButtons for ''rgCount'' (written among each other): ''1 5 10 20 50 100''
 +
* set the first RadioButton as the ''currently selected'', by setting the property ''ItemIndex'' of ''rgShape'' and ''rgCount'' from ''-1'' to ''0''
 +
* create the ''OnClick'' event handler of ''rgShape'' by double clicking ''rgShape''
 +
* also use these event handler for ''rgCount'':
 +
** in the Object Inspector select ''rgCount''
 +
** now select the tab ''Events'' in the Object Inspector
 +
** go to the ''OnClick'' event and select in the adjacent ComboBox ''rgShapeClick''
 +
* whenever ''rgShape'' or ''rgCount'' is clicked, the form should be redrawn, therefore write following code in the event handler:
 +
<syntaxhighlight lang="pascal">
 +
procedure TForm1.rgShapeClick(Sender: TObject);
 +
begin
 +
  Repaint;
 +
end;
 +
</syntaxhighlight>
 +
* whenever the form is redrawn, the shapes should be drawn:
 +
** in the Object Inspector select ''Form1''
 +
** select the tab ''Events''
 +
** click on the button [...] next to the event ''OnPaint''
 +
** the handler is created, enter the following code:
 +
<syntaxhighlight lang="pascal">
 +
procedure TForm1.FormPaint(Sender: TObject);
 +
var
 +
  i: Integer;
 +
begin
 +
  if TryStrToInt(rgCount.Items[rgCount.ItemIndex], i) then
 +
    for i:=1 to i do begin
 +
      Canvas.Pen.Color:=Random($1000000);
 +
      Canvas.Brush.Color:=Random($1000000);
 +
      case rgShape.Items[rgShape.ItemIndex] of
 +
        'Lines':      Canvas.Line(Random(ClientWidth), Random(ClientHeight), Random(ClientWidth), Random(ClientHeight));
 +
        'Rectangles': Canvas.Rectangle(Random(ClientWidth), Random(ClientHeight), Random(ClientWidth), Random(ClientHeight));
 +
        'Ellipses':  Canvas.Ellipse(Random(ClientWidth), Random(ClientHeight), Random(ClientWidth), Random(ClientHeight));
 +
      end;
 +
    end;
 +
end;
 +
</syntaxhighlight>
 +
* start your program, it could look like:
  
 +
[[image:ExampleTRadioGroup.png]]
  
 +
==See also==
 +
* [[doc:lcl/extctrls/tradiogroup.html|TRadioGroup doc]]
 +
* [[TRadioButton]]
 +
* [[TGroupBox]]
  
 
This is a stub page until completed
 
 
{{LCL Components Footer |TGroupBox|TCheckGroup}}
 
 
{{LCL Components}}
 
{{LCL Components}}
 
 
[[Category:Components]]
 

Latest revision as of 22:33, 17 April 2022

Deutsch (de) English (en) suomi (fi) français (fr) 日本語 (ja) русский (ru)

A TRadioGroup tradiogroup.png is a group of related but mutually exclusive TRadioButtons, requiring the user to select one of a set of alternatives. It's like a TGroupBox with integrated TRadioButtons.

Usage

To use a TRadioGroup on a form, you can simply select it on the Standard tab of the Component Palette and place it by clicking on the form.

Small example

Geometric figures should be drawn randomly and depending on the TRadioGroups to the form. The first RadioGroup determines the shape, the second RadioGroup detrmines the number.

  • create a new application and place two TRadioGroups on your form
  • change in the Object Inspector the property Name of RadioGroup1 to rgShape, also RadioGroup2 to rgCount
  • change identical Caption of rgShape to Shape and that of rgCount to Count
  • add the RadioButtons for rgShape:
    • in the Object Inspector select the property Items of rgShape
    • click on the button [...], the character chain editor opens
    • write among each other Lines Rectangles Ellipses and complete the entry with the button OK
  • add identical the RadioButtons for rgCount (written among each other): 1 5 10 20 50 100
  • set the first RadioButton as the currently selected, by setting the property ItemIndex of rgShape and rgCount from -1 to 0
  • create the OnClick event handler of rgShape by double clicking rgShape
  • also use these event handler for rgCount:
    • in the Object Inspector select rgCount
    • now select the tab Events in the Object Inspector
    • go to the OnClick event and select in the adjacent ComboBox rgShapeClick
  • whenever rgShape or rgCount is clicked, the form should be redrawn, therefore write following code in the event handler:
procedure TForm1.rgShapeClick(Sender: TObject);
begin
  Repaint;
end;
  • whenever the form is redrawn, the shapes should be drawn:
    • in the Object Inspector select Form1
    • select the tab Events
    • click on the button [...] next to the event OnPaint
    • the handler is created, enter the following code:
procedure TForm1.FormPaint(Sender: TObject);
var
  i: Integer;
begin
  if TryStrToInt(rgCount.Items[rgCount.ItemIndex], i) then
    for i:=1 to i do begin
      Canvas.Pen.Color:=Random($1000000);
      Canvas.Brush.Color:=Random($1000000);
      case rgShape.Items[rgShape.ItemIndex] of
        'Lines':      Canvas.Line(Random(ClientWidth), Random(ClientHeight), Random(ClientWidth), Random(ClientHeight));
        'Rectangles': Canvas.Rectangle(Random(ClientWidth), Random(ClientHeight), Random(ClientWidth), Random(ClientHeight));
        'Ellipses':   Canvas.Ellipse(Random(ClientWidth), Random(ClientHeight), Random(ClientWidth), Random(ClientHeight));
      end;
    end;
end;
  • start your program, it could look like:

ExampleTRadioGroup.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