![]() Note: Setting the radio group's BiDiMode to bdRightToLeft automatically flips its radio buttons. The value of the ItemIndex property determines which radio button is currently selected.ĭisplay the radio buttons in a single column or in multiple columns by setting the Columns property. ![]() Each string in Items makes a radio button appear in the group box with the string as its caption. To add radio buttons to a TRadioGroup, edit the Items property in the Object Inspector. Hence, two radio buttons on a form can be checked at the same time only if they are placed in separate containers, such as group boxes. Radio buttons that are placed directly in the same control component are said to be "grouped." When the user checks a radio button, all other radio buttons in its group become unchecked. If Assigned(Action) and (Action is TCustomAction) and TCustomAction(Action).TRadioGroup represents a group of radio buttons that function together.Ī TRadioGroup object is a special group box that contains only radio buttons. If (Sibling Self) and (Sibling is TRadioButton) and (Sibling.Tag = Self.Tag) then Procedure TRadioButton.SetChecked(Value: Boolean) TRadioButton = class()įunction TRadioButton.GetChecked: Boolean Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.Actions, Vcl.ActnList Here is the DPR source: program TRadioButtonGroupingWithTag This (ultimate) answer is based completely on Andreas Rejbrand's idea to use an interposer class only (without new components): Object GroupRadioButton4: TGroupRadioButtonĬaption = 'GroupRadioButton4 (GroupIndex=0)' Object GroupRadioButton3: TGroupRadioButtonĬaption = 'GroupRadioButton3 (GroupIndex=0)' Object GroupRadioButton2: TGroupRadioButtonĬaption = 'GroupRadioButton2 (GroupIndex=1)' Object GroupRadioButton1: TGroupRadioButtonĬaption = 'GroupRadioButton1 (GroupIndex=1)' Vcl.Controls, Vcl.Forms, Vcl.Dialogs, GroupRadioButton, Vcl.StdCtrls Īnd here is the DFM: object Form1: TForm1 Display the radio buttons in a single column or in multiple columns by. Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, The value of the ItemIndex property determines which radio button is currently selected. ![]() GroupRadioButton in 'GroupRadioButton.pas' RegisterComponents('PASoft', ) Īnd this is the package PackageGroupRadioButton.dpk: package PackageGroupRadioButton Procedure TGroupRadioButton.SetGroupIndex(const Value: Integer) SendMessage(Handle, BM_SETCHECK, WPARAM(FChecked), 0) If (Sibling Self) and (Sibling is TGroupRadioButton) and (TGroupRadioButton(Sibling).GroupIndex = Self.GroupIndex) then Procedure TGroupRadioButton.SetChecked(Value: Boolean) Winapi.Windows, Vcl.ActnList, Winapi.Messages įunction TGroupRadioButton.GetChecked: Boolean Property GroupIndex: Integer read FGroupIndex write SetGroupIndex Procedure SetGroupIndex(const Value: Integer) System.SysUtils, System.Classes, Vcl.Controls, Vcl.StdCtrls This is the latest version of my new component TGroupRadioButton in GroupRadioButton.pas (Note the new property GroupIndex): unit GroupRadioButton Then in a second step, I am planning to add a property GroupIndex, so that only controls with the same GroupIndex would be unchecked. However, In Objectinspector these 3 controls are still declared as TRadioButton!: Then I redeclared the 3 TRadioButton controls I want to become independent as TMyRadioButton: rbSortNone: TMyRadioButton ![]() You can see that I changed the TurnSiblingsOff procedure to consider only TMyRadioButton controls, so not to uncheck the remaining 2 TRadioButton controls. If not (csLoading in ComponentState) and IsCustomStyleActive and Visible then SendMessage(Handle, BM_SETCHECK, WPARAM(Checked), 0) If Assigned(Action) and (Action is TCustomAction) and TCustomAction(Action).AutoCheck then If (Sibling Self) and (Sibling is TMyRadioButton) then Procedure TMyRadioButton.SetChecked(Value: Boolean) Procedure SetChecked(Value: Boolean) override I want to use 3 of them as an INDEPENDENT Group without using a container control such as TPanel for these 3 TRadioButton controls, meaning that when I click on one of these 3 TRadioButton controls, the remaining 2 TRadioButton controls will not be unchecked.įor this purpose, I have overridden the protected SetChecked method in the TRadioButton class: type In a 32-bit VCL Application in Windows 10 in Delphi 11.1 Alexandria, I have 5 TRadioButton controls directly on a TRelativePanel.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |