TRadioGroup doesn't get events lazarus / 31-LCL ---------------------------------------------------------------------- meteoricshipyards · 2023-10-14 15:32 Trying out Lazarus, created an application with some radio button groups, and none of the OnClick or OnSelectionChanged routines were being activated.  Created a new project just for testing it: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    RadioButton1: TRadioButton;    RadioButton2: TRadioButton;    RadioButton3: TRadioButton;    RadioGroup1: TRadioGroup;    procedure GroupChanged(Sender: TObject);    procedure RadioGroup1Click(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.RadioGroup1Click(Sender: TObject);begin  ShowMessage('Clicked'); end; procedure TForm1.GroupChanged(Sender: TObject);begin  ShowMessage('Changed');end; end. The form looks fine, the radio buttons work, click one, and the other that was selected turns off.  Other testing shows the buttons are getting the OnClick event.  I could point the buttons to the group's OnClick procedure, but then I'd have to set the ItemIndex value manually, and I don't think that is how it's supposed to go. So, any suggestions?  I'm sure I'm missing something simple, but can't figure it out. Thanks. Tom A. "Oh sure, computers are great.  But I've only encountered one who offered to drive me home after a long night at the pub.  I think they are unsocial as a rule." - The InUncredible Adventures of Baron Karnath ---------------------------------------------------------------------- Josh · 2023-10-14 16:08 Hi Not sure I follow, attached proj that acts on firedevents and informs in the memo ---------------------------------------------------------------------- jamie · 2023-10-14 16:10 the RadioButtons are not part of the group. use the ITEMS property editor to add them ---------------------------------------------------------------------- Handoko · 2023-10-14 16:15 Try mine, it works: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Dialogs, ExtCtrls; type   { TForm1 }   TForm1 = class(TForm)    RadioGroup1: TRadioGroup;    procedure FormCreate(Sender: TObject);  procedure RadioGroup1SelectionChanged(Sender: TObject);  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  RadioGroup1.Items.Add('one');  RadioGroup1.Items.Add('two');  RadioGroup1.Items.Add('three');end; procedure TForm1.RadioGroup1SelectionChanged(Sender: TObject);var  S: string;begin  if not(Sender is TRadioGroup) then Exit;  case RadioGroup1.ItemIndex of    0: S := 'first';    1: S := 'second';    2: S := 'third';  end;  ShowMessage('You''ve just clicked the ' + S + ' item.');end; end. ---------------------------------------------------------------------- meteoricshipyards · 2023-10-14 19:12 "the RadioButtons are not part of the group. use the ITEMS property editor to add them" Thank you.  I created the TRadioGroup, then clicked on TRadioButton in the controls, and placed them in the group on the visual form editor.  Not sure if it's my reading comprehension or the documentation that's at fault.  There is a video on YouTube that did it the same way I did (but didn't show any processing based on the radio buttons.) So thank you again! Tom A. "While I was greatful that the computer drove me home when I was in no condition to, I was less happy when I found it had driven off with my car, and when it was recovered, it was tireless.  As it was a Rylos Starcar, it took months before I was able to get them replaced." - The InUncredible Adventures of Baron Karnath ---------------------------------------------------------------------- wp · 2023-10-14 20:38 Quote from: meteoricshipyards on October 14, 2023, 09:12:46 pmI created the TRadioGroup, then clicked on TRadioButton in the controls, and placed them in the group on the visual form editor.  This might work - but will be a mess and break the default operation of a TRadioGroup... TRadioGroups has built-in RadioButtons. You add such built-in radiobuttons when you click on the '...' next to the Items property of the RadioGroup and enter the captions of each radiobutton, line by line. TRadioGroup.ItemIndex is the index of the selected radiobutton in the group. When you select a different button within the group ItemIndex changes, and an event OnClick fires. That's all you need because you (almost) never need to access the individual radiobuttons You can add any other control to the RadioGroup because it is basically just a TGroupbox which is designed for containing arbitrary controls. But this is very complicated - see below. It is particularly complicated when you add another radiobutton to the group because the user will not be able to distinguish this button from the built-in ones. Since that additional button is not maintained by the RadioGroup, it is not an element of the internal Buttons list, and no TRadioGroup.OnClick event will fire when it is selected (however, there will be an OnClick event of this particular button!), and ItemIndex will not count it either. The attached demo shows these issues. It contains a TRadioGroup with three internal radiobuttons (labeled "Internal N", N = 1, 2, 3), and I dropped another isolated TRadioButton on the group keeping its default name, "RadioButton1". So, it looks as if there are four radiobuttons in the group - but the RadioGroup itself know only of three! Click on the "Number of radiobuttons in the group" button to query the number of buttons known to the radiogroup. The project also monitors the relevant events and logs them in the memo along with the index of the current value of the ItemIndex. Click on one of the three "Internal" buttons - everything is correct: a TRadioGroup.OnClick event fires. But when you click on the additional button, things go crazy: The RadioGroup ItemIndex goes to -1, and the additional radiobutton fires an onChange event... Don't do this: Never add a TRadioButton to a TRadioGroup. Always use the Items property. Sometimes, however, it may be required to have, for example, edit controls next to the radiobuttons. Normally this would be done by using a TGroupBox (which does not contain any internal controls) and add radiobuttons and the needed edits. But it can be achieved also with the RadioGroup: Add three items to the radiogroup (by means of the "Items" property), then drop three TEdit controls on the radiogroup. The edits are added at the end of radiobutton list. In order to place them to the right of the radiobuttons you must know that the TRadioGroup manages the positioning of its controls by the ChildSizing property. Select the radiogroup and open the ChildSizing subproperties. Change Layout to cclTopToBottomThenLeftToRight and then ControlsPerLine to 3 (this is badly named, it means "Controls per column" when the columns are filled first) - now the edits are at the right of the radiobuttons. If you want some spacing between them adjust the VerticalSpacing and TopBottomSpacing values.