From 830ac027c9906e3d93cb9fa8d848188ed5e8a3fc Mon Sep 17 00:00:00 2001 From: Juha Date: Sat, 24 Aug 2024 21:12:58 +0300 Subject: [PATCH] LCL: Prevent crash in RadioGroup when hidden radiobutton is selected by arrow keys. Issue #41093. (cherry picked from commit 48cf66858d9c31a57caf416ddc053760eef85243) --- lcl/include/radiogroup.inc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lcl/include/radiogroup.inc b/lcl/include/radiogroup.inc index c37fb3ed5a..33caa17f99 100644 --- a/lcl/include/radiogroup.inc +++ b/lcl/include/radiogroup.inc @@ -264,6 +264,7 @@ procedure TCustomRadioGroup.ItemKeyDown(Sender: TObject; var Key: Word; BlockSize : integer; NewIndex : integer; WrapOffset: integer; + Butt: TRadioButton; begin Count := FButtonList.Count; if FColumnLayout=clHorizontalThenVertical then begin @@ -287,9 +288,11 @@ procedure TCustomRadioGroup.ItemKeyDown(Sender: TObject; var Key: Word; while NewIndex >= Count do NewIndex := (NewIndex + StepSize) mod BlockSize; end; - until (NewIndex = ItemIndex) or TRadioButton(FButtonList[NewIndex]).Enabled; + Butt := TRadioButton(FButtonList[NewIndex]); + until (NewIndex = ItemIndex) or (Butt.Visible and Butt.Enabled); ItemIndex := NewIndex; - TRadioButton(FButtonList[ItemIndex]).SetFocus; + if Butt.CanSetFocus then // ItemIndex = NewIndex, Butt is still valid. + Butt.SetFocus; Key := 0; end;