Radiogroup selection clear lazarus / 31-LCL ---------------------------------------------------------------------- badmintonfan · 2023-05-23 03:31 I try to clear radio group selection via the following code try     radiogroup1.itemindex := -1 except end; but always the error message release that list index(-1) out of bounds is there any way to clear the selection,back to initiation ---------------------------------------------------------------------- Handoko · 2023-05-23 03:49 Can you provide a demo? I tried to do what you said but I didn't get the error. Or maybe you can try my demo below. 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, Forms, Controls, Dialogs, ExtCtrls, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    RadioGroup1: TRadioGroup;    procedure Button1Click(Sender: TObject);  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin  try    RadioGroup1.ItemIndex := -1;  except    ShowMessage('Error');  end;end; end. ---------------------------------------------------------------------- TRon · 2023-05-23 03:55 As a shot in the dark, do you perhaps have an event assigned to the buttons and use the (invalid) index there ? ---------------------------------------------------------------------- badmintonfan · 2023-05-23 06:02 Quote from: Handoko on May 23, 2023, 05:49:52 amCan you provide a demo? I tried to do what you said but I didn't get the error. Or maybe you can try my demo below. 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, Forms, Controls, Dialogs, ExtCtrls, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    RadioGroup1: TRadioGroup;    procedure Button1Click(Sender: TObject);  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin  try    RadioGroup1.ItemIndex := -1;  except    ShowMessage('Error');  end;end; end.Here is code at onclick section procedure TForm1.RadioGroup1Click(Sender: TObject); var s : string; begin     s:= radiogroup1.Items[radiogroup1.ItemIndex];     showmessage(s);     try     radiogroup1.ItemIndex:= -1;     except     ShowMessage('Error');     end; end; ---------------------------------------------------------------------- dseligo · 2023-05-23 06:07 Quote from: badmintonfan on May 23, 2023, 08:02:02 amHere is code at onclick section procedure TForm1.RadioGroup1Click(Sender: TObject); var s : string; begin     s:= radiogroup1.Items[radiogroup1.ItemIndex];     showmessage(s);     try     radiogroup1.ItemIndex:= -1;     except     ShowMessage('Error');     end; end;      Try: 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 procedure TForm1.RadioGroup1Click(Sender: TObject);var s : string;begin    If radiogroup1.ItemIndex >= 0 then        s:= radiogroup1.Items[radiogroup1.ItemIndex]    else        s := 'no item selected';    showmessage(s);    try    radiogroup1.ItemIndex:= -1;  except    ShowMessage('Error');    end; end; ---------------------------------------------------------------------- badmintonfan · 2023-05-23 06:27 Thanks, it works!