Selecting disabled item in TRadioGroup
Original Reporter info from Mantis: giovanni.seara
-
Reporter name: Giovanni Seara
Original Reporter info from Mantis: giovanni.seara
- Reporter name: Giovanni Seara
Description:
When RadioGroup has any items disabled, when browsing through VK_DOWN, the disabled item is selected and an exception is generated.
Steps to reproduce:
1 - 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 information:
The 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;
Mantis conversion info:
- Mantis ID: 33386
- OS: Windows
- OS Build: 10
- Platform: Desktop
- Version: 1.9 (SVN)
- Fixed in revision: 57483 (#f0012094)
- Monitored by: » giovanni.seara (Giovanni Seara)
- Target version: 1.8.4