Project JEDI - Issue Tracker
Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0006277 [JEDI VCL] 00 JVCL Components minor always 2014-04-28 17:08 2014-12-04 14:57
Reporter sp40 View Status public  
Assigned To
Priority normal Resolution open  
Status acknowledged   Product Version 3.45
Summary 0006277: Focus with TJvDbGrid - TWebBrowser
Description I put a TJvDbGrid and a TWebBrowser on my form.
As I select a cell in my grid, I load the adress from table displayed in the JvdbGrid (some GoogleMaps location). If I click on the webBrowser, the jvDbGrid seems to lost focus, and I can't change the selected record.
I can catch the focus back on the jvdbgrid as I click in a ComboBox before.
Additional Information This bug was told on the native DBGrid. I've overloaded the fix on the TJvDbGrid and it fixes it too.
( [^]

The answer was :
For everybody - problem with DBGrid is fixed now...
How? Error was in DBGrid not in TWebBrowser...
Compile unit from this mail and use TFixedDBGrid instead of TDBGrid...

Enjoy now it...!

Milan Kajnar

unit FixedDBGrid;


Winprocs,wintypes, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, Grids, DBGrids;

TFixedDBGrid = class(TDBGrid)
{ Private declarations }
{ Protected declarations }
{ Public declarations }
procedure WMRButtonDown(var Message: TWMRButtonDown); message
procedure WMLButtonDown(var Message: TWMLButtonDown); message
{ Published declarations }

procedure Register;


procedure TFixedDBGrid.WMRButtonDown(var Message: TWMRButtonDown);
winprocs.SetFocus(handle); {remember that winprocs in Delphi 1

procedure TFixedDBGrid.WMLButtonDown(var Message: TWMLButtonDown);
winprocs.SetFocus(handle); {remember that winprocs in Delphi 1

procedure Register;
RegisterComponents('Samples', [TFixedDBGrid]);


Tags No tags attached.
Attached Files rar file icon Demo Grid.rar [^] (3,935,899 bytes) 2014-09-04 10:57

- Relationships

-  Notes
sp40 (reporter)
2014-04-28 17:11 [^]
AHUser (developer)
2014-04-28 22:09

> Error was in DBGrid not in TWebBrowser

Actually the bug is in the COM-Container that hosts the TWebBrowser. The IWebBrowser takes the focus but the VCL isn't notified correctly and still thinks the Grid has the focus. So the Grid's TWinControl.SetFocus call from MouseDown doesn't do anything because FocusedControl is already the Grid.

Your bug fix is a work around by using Windows.SetFocus to circumvent the "if FocusedControl <> Grid" check.
sp40 (reporter)
2014-04-29 09:19

I don't know about the TWebBrowser, but I trust you... :)
The "bug fix" isn't mine (it's a quotation from Milan Kajnar).

It's strange by the way that others controls can catch the focus back... If you put a combo, a checkbox or an edit, there's no problem at all.
AHUser (developer)
2014-05-01 16:15
edited on: 2014-05-01 16:17

> If you put a combo, a checkbox or an edit, there's no problem at all.

Those controls are "real" Windows controls and use the Windows.SetFocus function if you click on them. But DBGrid depends on the VCL's FocusedControls to be in sync with the actual "GetFocus" window handle. And DBGrid has this code in it

  SetFocus; // VCL's SetFocus
  if not Focused then Exit; // uses Windows.GetFocus = Self.Handle

And because the VCL's FocusedControl is out of sync with the actual focused window handle, the "if not Focused then Exit" stops the MouseDown handler from being processed. The purpose of this code in DBGrid is to handle the InplaceEdit controls. But it fails if VCL's focus and Windows's focus are out of sync.

Every VCL control that uses the "function Focused: Boolean" function will run into a problem with the TWebBrowser.

obones (administrator)
2014-09-03 11:43

Please provide the zipped sources of a sample application showing this
sp40 (reporter)
2014-09-04 10:59

Sample application uploaded

- Issue History
Date Modified Username Field Change
2014-04-28 17:08 sp40 New Issue
2014-04-28 17:11 sp40 Note Added: 0020955
2014-04-28 22:09 AHUser Note Added: 0020956
2014-04-29 09:19 sp40 Note Added: 0020957
2014-05-01 16:15 AHUser Note Added: 0020958
2014-05-01 16:16 AHUser Note Edited: 0020958
2014-05-01 16:17 AHUser Note Edited: 0020958
2014-09-03 11:43 obones Note Added: 0021042
2014-09-03 11:43 obones Status new => feedback
2014-09-04 10:57 sp40 File Added: Demo Grid.rar
2014-09-04 10:59 sp40 Note Added: 0021048
2014-12-04 14:57 obones Status feedback => acknowledged

Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker