急 ! ! ! ! ! ! ! !请问关于dbgrid和webbrowser的焦点有关问题

急! ! !急! ! !急! ! !急! ! !:请教关于dbgrid和webbrowser的焦点问题
在一窗体中有一dbgrid和webbrowser, 在webbrowser载入一个页面后,载入的页面也没有连接,鼠标在webbrowser上随便点几下,然后再回点dbgrid,此时dbgrid的单击双击事件都不会执行,整行选中状态也不会显示。  
   
   如果再点击了两外的控件,如treeview or text等,再回点dbgrid就可以了。为什么会是这样了?如何可以保持dbgrid中的一条记录保持选中状态下的高亮形式,并且点击webbrowser之后,再回点dbgrid单击和双击事件都能执行。  
   在线等待。分不够,可以再开贴给分。  
   详细一些最好,要不给个能实际实现功能的具体方法也行。  
 

------解决方案--------------------
Query.Locate('字段名称',Trim(Edit1.Text),[loCaseInsensitive ,loPartialKey]); 这样写就可以了

------解决方案--------------------
關于焦點問題,沒有很好的解決辦法。
應該說,這是一個vcl的bug。
從其他winControl移動到webbrowser時,會執行focusControl動作,但我們選擇的是web的元素,focus失敗,整個過程就停止在這里。所以后續給之前擁有焦點的wincontrol發送cm_exit消息也沒執行,onexit事件也就不會被觸發了。正常來講,只要焦點有正常切換,onexit都會被觸發的。

一個暫時的解決辦法是,在webbrowser.onStatusTextChange里這樣寫
Delphi(Pascal) code

  if ActiveControl<>Sender then
    ActiveControl := nil;

------解决方案--------------------
由于原先activeControl沒有切換成功,所以還是保留上次的擁有焦點的wincontrol。當你想操作這個wincontrol時,VCL就認為,這個control已經有焦點了,后續動作就不執行了(window.setfocus),這樣就使得很多消息無法接收(如鼠標消息,鍵盤消息)。
------解决方案--------------------
結合一下VCL就更清楚了
Delphi(Pascal) code

procedure TCustomForm.SetActiveControl(Control: TWinControl);
begin
  if FActiveControl <> Control then
  begin
    if not ((Control = nil) or (Control <> Self) and
      (GetParentForm(Control) = Self) and ((csLoading in ComponentState) or
        Control.CanFocus)) then
      raise EInvalidOperation.Create(SCannotFocus);
    FActiveControl := Control;
    if not (csLoading in ComponentState) then
    begin
      if FActive then SetWindowFocus;
      ActiveChanged;
    end;
  end;
end;