View Issue Details

IDProjectCategoryView StatusLast Update
0006277JEDI VCL00 JVCL Componentspublic2014-12-04 14:57
Reportersp40Assigned To 
Status acknowledgedResolutionopen 
Product Version3.45 
Target VersionFixed in Version 
Summary0006277: Focus with TJvDbGrid - TWebBrowser
DescriptionI 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 InformationThis 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]);


TagsNo tags attached.



2014-04-28 17:11

reporter   ~0020955


2014-04-28 22:09

developer   ~0020956

> 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.


2014-04-29 09:19

reporter   ~0020957

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.


2014-05-01 16:15

developer   ~0020958

Last edited: 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.


2014-09-03 11:43

administrator   ~0021042

Please provide the zipped sources of a sample application showing this

2014-09-04 10:57


Demo Grid.rar (3,935,899 bytes)


2014-09-04 10:59

reporter   ~0021048

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