View Issue Details

IDProjectCategoryView StatusLast Update
0005723JEDI VCL00 JVCL Componentspublic2012-09-10 14:15
ReporterAriochAssigned Toobones 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product VersionDaily / GIT 
Target VersionFixed in Version3.46 
Summary0005723: JvCheckbox in JvCheckBox.pas is broken on transfering focus
DescriptionThe widget has LinkedControls list, which it tries to enable/disable wrt its checkmark toggle.

But it also tries to lend its focus to the 1st of them. And if check is clear, then it tries to Focus disabled control, which then throws an Exception.

(to reproduce it you should switch focus with tab / shift-tab, because mouse just checks the mark and control becomes enabled and focusing goes ok)

Looks like current code only function is just to find 1st TWinControl and unconditionally focus it, so i reworked it a bit.
Steps To ReproduceCurrent code:

procedure TJvCheckBox.SetFocus;
var
  I: Integer;
  FocusLinkedControl: TControl;
begin
  inherited SetFocus;

  FocusLinkedControl := nil;
  I := 0;
  while (I < LinkedControls.Count) and not Assigned(FocusLinkedControl) do
  begin
    if (loForceFocus in LinkedControls[I].Options) and (LinkedControls[I].Control is TWinControl) then
      FocusLinkedControl := LinkedControls[I].Control;

    Inc(I);
  end;
  if Assigned(FocusLinkedControl) then
    TWinControl(FocusLinkedControl).SetFocus;
end;
Additional InformationProposed change:

procedure TJvCheckBox.SetFocus;
var
  I: Integer;
  TryControl: TJvLinkedControl;
// FocusLinkedControl: TWinControl;
begin
  inherited SetFocus;

  for I := 0 to LinkedControls.Count - 1 do begin
    TryControl := LinkedControls[I]; // let cache and speed up a bit
    if (loForceFocus in TryControl.Options) and (TryControl.Control is TWinControl) then
       with TWinControl(TryControl.Control) do
            if CanFocus then begin
               SetFocus;
               Break;
            end;
  end;
end;
TagsNo tags attached.

Activities

Arioch

2011-11-27 19:46

developer   ~0019142

I wonder if enumerator-based for-in construct would be better for modern Delphies and there's sense to have IfDef-ed code ?

But probably not. For most time there would be 1 or at large just 3-4 linked controls, where overhead of creating two objects (GetEnumerable -> GetEnumerator) is not worth the candles. Though for-in is slick and elegant to read.

Arioch

2011-11-30 20:46

developer   ~0019169

this was in Eclipse in "Steps to reproduce" section. Seems is not available in WWW:
=============================
Current code:

procedure TJvCheckBox.SetFocus;
var
  I: Integer;
  FocusLinkedControl: TControl;
begin
  inherited SetFocus;

  FocusLinkedControl := nil;
  I := 0;
  while (I < LinkedControls.Count) and not Assigned(FocusLinkedControl) do
  begin
    if (loForceFocus in LinkedControls[I].Options) and (LinkedControls[I].Control is TWinControl) then
      FocusLinkedControl := LinkedControls[I].Control;

    Inc(I);
  end;
  if Assigned(FocusLinkedControl) then
    TWinControl(FocusLinkedControl).SetFocus;
end;

obones

2012-02-22 15:01

administrator   ~0019456

Please provide the zipped sources of a sample application showing this

2012-02-22 22:12

 

JVCL_5723.exe.7z (1,742,503 bytes)

2012-02-22 22:14

 

JVCL-0005723.sources.7z (1,206 bytes)

Arioch

2012-04-15 15:46

developer   ~0019701

bump

obones

2012-06-12 16:03

administrator   ~0019925

This is now fixed in SVN

Issue History

Date Modified Username Field Change
2011-11-27 19:32 Arioch New Issue
2011-11-27 19:36 Arioch Description Updated
2011-11-27 19:36 Arioch Additional Information Updated
2011-11-27 19:46 Arioch Note Added: 0019142
2011-11-30 20:46 Arioch Note Added: 0019169
2011-12-29 22:57 Arioch Status new => closed
2011-12-29 22:57 Arioch Resolution open => fixed
2011-12-29 22:57 Arioch Fixed in Version => Daily / SVN
2011-12-29 22:58 Arioch Status closed => feedback
2011-12-29 22:58 Arioch Resolution fixed => reopened
2011-12-29 22:58 Arioch Status feedback => new
2012-02-22 15:01 obones Note Added: 0019456
2012-02-22 15:01 obones Status new => feedback
2012-02-22 22:12 Arioch File Added: JVCL_5723.exe.7z
2012-02-22 22:14 Arioch File Added: JVCL-0005723.sources.7z
2012-04-15 15:46 Arioch Note Added: 0019701
2012-06-11 17:39 obones Status feedback => acknowledged
2012-06-12 16:03 obones Note Added: 0019925
2012-06-12 16:03 obones Status acknowledged => resolved
2012-06-12 16:03 obones Resolution reopened => fixed
2012-06-12 16:03 obones Assigned To => obones
2012-09-10 14:15 obones Fixed in Version Daily / SVN => 3.46