View Issue Details

IDProjectCategoryView StatusLast Update
0037385LazarusLCLpublic2020-09-30 11:25
ReporterZdravko Gabrovski Assigned ToJuha Manninen  
Status closedResolutionfixed 
Summary0037385: DBGrid raises "Can not focus to disable or invisible window" when hides inplace editor
DescriptionDBGrid raises "Can not focus to disabe or invisible window" when hide inplace editor after enable dataset controls.
To reproduce the problem you must enable "dgAlwaysShowEditor" option.
In my case I have a page control with 2 tab controls. In first one there is a DBGrid with dgAlwaysShowEditor set to true.
When user change the active tab sheet, I do a dataset "DisableControls", some work over the data, and after that "EnableControls".
All this happens in PageControl "OnChange" event handler.
After "Enablecontrols" it fire "Can not focus to disable or invisible window" exception.

The exception comes from line 7215 in Grids.pas file in DoEditorHide method.
ParentForm.ActiveControl := self;

To solve the case, I just add a sanity check:

    if Self.CanFocus then
      ParentForm.ActiveControl := self;

Steps To ReproducePlease, use attached example.
1. Click button "Delete"
2. Click over "TabSheet2".
It will raise exception.
Additional InformationI catch the bug over Win32/64 lcl, but may be there is the same problem over all other widgetsets.
TagsNo tags attached.
Fixed in Revisionr63596
Attached Files


Zdravko Gabrovski

2020-07-18 05:51


grid.diff (612 bytes)   
Index: lazarus/lcl/grids.pas
--- lazarus/lcl/grids.pas	(revision 63438)
+++ lazarus/lcl/grids.pas	(working copy)
@@ -7212,7 +7212,8 @@
   {$ifdef dbgGrid}DebugLnEnter('grid.DoEditorHide [',Editor.ClassName,'] INIT');{$endif}
   if gfEditingDone in FGridFlags then begin
     ParentForm := GetParentForm(Self);
-    ParentForm.ActiveControl := self;
+    if Self.CanFocus then
+      ParentForm.ActiveControl := self;
   {$ifdef dbgGrid}DebugLnExit('grid.DoEditorHide [',Editor.ClassName,'] END');{$endif}
grid.diff (612 bytes)   

Zdravko Gabrovski

2020-07-18 05:52

reporter   ~0124138

Last edited: 2020-07-18 05:52

View 2 revisions

Please find attached sample project
GridPatch.7z (53,773 bytes)

Juha Manninen

2020-07-18 23:58

developer   ~0124160

Applied, thanks.

Zdravko Gabrovski

2020-07-21 20:48

reporter   ~0124217

you are welcome!

Zdravko Gabrovski

2020-09-30 11:25

reporter   ~0125982


Issue History

Date Modified Username Field Change
2020-07-18 05:51 Zdravko Gabrovski New Issue
2020-07-18 05:51 Zdravko Gabrovski File Added: grid.diff
2020-07-18 05:52 Zdravko Gabrovski Note Added: 0124138
2020-07-18 05:52 Zdravko Gabrovski File Added: GridPatch.7z
2020-07-18 05:52 Zdravko Gabrovski Note Edited: 0124138 View Revisions
2020-07-18 23:58 Juha Manninen Assigned To => Juha Manninen
2020-07-18 23:58 Juha Manninen Status new => assigned
2020-07-18 23:58 Juha Manninen Status assigned => resolved
2020-07-18 23:58 Juha Manninen Resolution open => fixed
2020-07-18 23:58 Juha Manninen Fixed in Revision => r63596
2020-07-18 23:58 Juha Manninen LazTarget => -
2020-07-18 23:58 Juha Manninen Widgetset Win32/Win64 => Win32/Win64
2020-07-18 23:58 Juha Manninen Note Added: 0124160
2020-07-21 20:48 Zdravko Gabrovski Note Added: 0124217
2020-09-30 11:25 Zdravko Gabrovski Status resolved => closed
2020-09-30 11:25 Zdravko Gabrovski Note Added: 0125982