2

Mike Lischke のVirtual Treeviewには、同じフォームでTWebBrowserコントロールを使用する際のバグを修正するための回避策コードが追加されています。

問題は、ユーザーが( TWebBrowserが派生する) TOleControlと対話しようとすると、最初のマウス クリックが食べられることでした。コントロールにフォーカスを与えるには、もう一度クリックする必要があります。次に、コントロールを操作できます。

彼は説明するコメントを持っています:

から派生したすべてのコントロールにTOleControlは、潜在的にフォーカスの問題があります。

クラスのテストを可能にするOleCtrlsユニット (特に、 Variantを含む) を含めることを避けるために、インターフェースがテストに使用されます。TOleControlIOleClientSiteTOleControl

完全なスニピットから:

procedure TBaseVirtualTree.WMKillFocus(var Msg: TWMKillFocus);
var
  Form: TCustomForm;
  Control: TWinControl;
  Pos: TSmallPoint;
  Unknown: IUnknown;
begin
  inherited;

  [snip]

  {
    Workaround for wrapped non-VCL controls (like TWebBrowser), 
    which do not use VCL mechanisms and 
    leave the ActiveControl property in the wrong state, 
    which causes trouble when the control is refocused.
  }
  Form := GetParentForm(Self);
  if Assigned(Form) and (Form.ActiveControl = Self) then
  begin
    Cardinal(Pos) := GetMessagePos;
    Control := FindVCLWindow(SmallPointToPoint(Pos));
    {
      Every control derived from TOleControl has potentially 
      the focus problem. In order to avoid including 
      the OleCtrls unit (which will, among others, include Variants),  
      which would allow to test for the TOleControl
      class, the IOleClientSite interface is used for the test, 
      which is supported by TOleControl and a good indicator.
    }
    if Assigned(Control) and Control.GetInterface(IOleClientSite, Unknown) then
      Form.ActiveControl := nil;

    // For other classes the active control should not be modified. Otherwise you need two clicks to select it.
  end;
end;

問題は、回避策が機能しなくなったことです。正直なところ、問題が実際に何であったのか、彼のソリューションがどのようにそれを修正したのか、私にはわかりません。

彼のコメントが彼の言っていることを理解していることを知っていて、問題が何であるかを説明でき、彼がしていることはそれをどのように修正することになっていたかを知っている人はいますか?

ラップされた非 VCL コントロール (TWebBrowser など) の回避策。これらは VCL メカニズムを使用せず、ActiveControl プロパティを間違った状態のままにして、コントロールが再びフォーカスされるときに問題を引き起こします。TOleControl から派生したすべてのコントロールには、潜在的にフォーカスの問題があります。

コードは意図した範囲に到達しています

Form.ActiveControl := nil; 

ステートメントですが、それはうまくいきません。

私はそれを修正したいと思いますが、彼がどのようにしてそれを見つけたのか、またはTOleControlが「VCL メカニズムを使用せず、ActiveControl プロパティを間違った状態のままにする」ことがどのように発生するのかわかりません。


ボーナスリーディング

私はもともと2008年ニュースグループでこの質問をしましたborland.public.delphi.nativeapi.win32

Soft-Gems フォーラムに関する質問

バンプ 20110515 (12 か月後)

バンプ 20150401 (7 年後): まだ XE6 で動作しない

バンプ 20210309 (11 年後)

4

1 に答える 1