View Issue Details

IDProjectCategoryView StatusLast Update
0033386PackagesLCLpublic2018-03-09 15:10
ReporterGiovanni Seara Assigned Towp  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformDesktopOSWindows 
Product Version1.9 (SVN) 
Target Version1.8.4 
Summary0033386: Selecting disabled item in TRadioGroup
DescriptionWhen RadioGroup has any items disabled, when browsing through VK_DOWN, the disabled item is selected and an exception is generated.
Steps To Reproduce1 - Add one TRadioGroup in the Form.
2 - Add four items in the TRadioGroup.
3 - Disable the second and third items of TRadioGroup.
4 - Execute the Form.
5 - Whith the Form executing, click in the first item of the TRadioGroup.
6 - Press VK_DOWN (At this point, the button of Item2 is checked and the focus is on item 4. An exception has been raised).
7 - Press VK_DOWN again (At this point, the Item3 button is checked and the focus is on Item1. An exception has also been raised).

Additional InformationThe possible fix for the error is to change the ItemKeyDown procedure of the TCustomRadioGroup:

procedure TCustomRadioGroup.ItemKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
  procedure MoveSelection(HorzDiff, VertDiff: integer);
  var
    Count: integer;
    StepSize: integer;
    BlockSize : integer;
    NewIndex : integer;
    WrapOffset: integer;
  begin
    Count := FButtonList.Count;
    if FColumnLayout=clHorizontalThenVertical then begin
      //add a row for ease wrapping
      BlockSize := Columns * (Rows+1);
      StepSize := HorzDiff + VertDiff * Columns;
      WrapOffSet := VertDiff;
    end
    else begin
      //add a column for ease wrapping
      BlockSize := (Columns+1) * Rows;
      StepSize := HorzDiff * Rows + VertDiff;
      WrapOffSet := HorzDiff;
    end;
    NewIndex := ItemIndex + StepSize;

    { Code correct }
    while ((NewIndex>=Count) or (NewIndex<0)) or
      not TRadioButton(FButtonList[NewIndex]).Enabled do
      NewIndex := (NewIndex + StepSize) mod BlockSize;
 
    { Code wrong
    if (NewIndex>=Count) or (NewIndex<0) then begin
      NewIndex := (NewIndex + WrapOffSet + BlockSize) mod BlockSize;
      // Keep moving in the same direction until in valid range
      while NewIndex>=Count do
        NewIndex := (NewIndex + StepSize) mod BlockSize;
    end; }

    ItemIndex := NewIndex;
    TRadioButton(FButtonList[ItemIndex]).SetFocus;
    Key := 0;
  end;
  
begin
  if Shift=[] then begin
    case Key of
      VK_LEFT: MoveSelection(-1,0);
      VK_RIGHT: MoveSelection(1,0);
      VK_UP: MoveSelection(0,-1);
      VK_DOWN: MoveSelection(0,1);
    end;
  end;
  if Key <> 0 then
    KeyDown(Key, Shift);
end;
TagsExtCtrls, lcl, RadioGroup
Fixed in Revision57483
LazTarget1.8.4
WidgetsetWin32/Win64
Attached Files

Activities

Giovanni Seara

2018-03-08 15:56

reporter  

Giovanni Seara

2018-03-08 15:57

reporter  

BUG - TRadioGroup.zip (2,478 bytes)

Vojtech Cihak

2018-03-08 16:13

reporter   ~0107007

@ 3 - Disable the second and third items of TRadioGroup.

I'm not sure if TRadioGroup was designed for this kind of hacking.

Giovanni Seara

2018-03-08 16:44

reporter   ~0107008

@Vojtech - Then in TRadioGroup can never have disable item?

wp

2018-03-08 17:04

developer   ~0107009

Last edited: 2018-03-08 17:05

View 2 revisions

This patch needs improvement:

If I disable the first and last button, i.e. the exact opposite compared to the description, select item 2 with the button, and press the UP arrow twice, the program hangs.

If I do not disable any button, press the button to select item 2, press arrow UP, nothing happens.

If I do not disable any button, click on item 1, press arrow up, nothing happens. If I press arrow down, the next item is selected. When the last item is reached the selection returns to item1 upon the next arrow up. This behavior is different to item 1 (which does not cycle).

If I do not disable any button, select Columns = 2, then the current (unpatched) behavior is this:
Click at Item 1. Press arrow right several times. The items are selected in the sequence 2-3-4-1. Press arrow down (starting at item1) - the sequence is 3-2-4-1.
With the patch the sequence is correct for arrow-right. But for arrow down the sequence never leaves the column, i.e. starting at 1: 1-3-1-3-1-3, or starting at 2: 2-4-2-4-2-

Serge Anvarov

2018-03-09 02:10

reporter  

radiogroup.diff (1,187 bytes)   
Index: lcl/include/radiogroup.inc
===================================================================
--- lcl/include/radiogroup.inc	(revision 57474)
+++ lcl/include/radiogroup.inc	(working copy)
@@ -278,13 +278,16 @@
       StepSize := HorzDiff * Rows + VertDiff;
       WrapOffSet := HorzDiff;
     end;
-    NewIndex := ItemIndex + StepSize;
-    if (NewIndex>=Count) or (NewIndex<0) then begin
-      NewIndex := (NewIndex + WrapOffSet + BlockSize) mod BlockSize;
-      // Keep moving in the same direction until in valid range
-      while NewIndex>=Count do
-        NewIndex := (NewIndex + StepSize) mod BlockSize;
-    end;
+    NewIndex := ItemIndex;
+    repeat
+      Inc(NewIndex, StepSize);
+      if (NewIndex>=Count) or (NewIndex<0) then begin
+        NewIndex := (NewIndex + WrapOffSet + BlockSize) mod BlockSize;
+        // Keep moving in the same direction until in valid range
+        while NewIndex>=Count do
+          NewIndex := (NewIndex + StepSize) mod BlockSize;
+      end;
+    until (NewIndex = ItemIndex) or TRadioButton(FButtonList[NewIndex]).Enabled;
     ItemIndex := NewIndex;
     TRadioButton(FButtonList[ItemIndex]).SetFocus;
     Key := 0;
radiogroup.diff (1,187 bytes)   

Serge Anvarov

2018-03-09 02:11

reporter   ~0107022

Add patch

wp

2018-03-09 09:47

developer   ~0107031

Thanks. Applied. Please test and close if ok.

Giovanni Seara

2018-03-09 15:10

reporter   ~0107052

Thanks for correction Serge Anvarov.

Issue History

Date Modified Username Field Change
2018-03-08 15:56 Giovanni Seara New Issue
2018-03-08 15:56 Giovanni Seara File Added: Video_1520503377.wmv
2018-03-08 15:57 Giovanni Seara Tag Attached: lcl
2018-03-08 15:57 Giovanni Seara Tag Attached: ExtCtrls
2018-03-08 15:57 Giovanni Seara Tag Attached: RadioGroup
2018-03-08 15:57 Giovanni Seara File Added: BUG - TRadioGroup.zip
2018-03-08 16:13 Vojtech Cihak Note Added: 0107007
2018-03-08 16:44 Giovanni Seara Note Added: 0107008
2018-03-08 17:04 wp Note Added: 0107009
2018-03-08 17:04 wp LazTarget => -
2018-03-08 17:04 wp Status new => acknowledged
2018-03-08 17:05 wp Note Edited: 0107009 View Revisions
2018-03-09 02:10 Serge Anvarov File Added: radiogroup.diff
2018-03-09 02:11 Serge Anvarov Note Added: 0107022
2018-03-09 09:41 wp Assigned To => wp
2018-03-09 09:41 wp Status acknowledged => assigned
2018-03-09 09:47 wp Fixed in Revision => 57483
2018-03-09 09:47 wp LazTarget - => 1.8.4
2018-03-09 09:47 wp Note Added: 0107031
2018-03-09 09:47 wp Status assigned => resolved
2018-03-09 09:47 wp Resolution open => fixed
2018-03-09 09:47 wp Target Version => 1.8.4
2018-03-09 15:10 Giovanni Seara Note Added: 0107052
2018-03-09 15:10 Giovanni Seara Status resolved => closed