在 Mike Lischke 的Virtual Treeview 中,添加了解决方法代码以修复在同一窗体上使用TWebBrowser控件时出现的错误。
问题在于,如果用户尝试与TOleControl(TWebBrowser 从中下降)进行交互,第一次鼠标点击就会被吃掉。然后他们必须再次单击以赋予控制焦点。然后他们可以与控件交互。
他有评论要解释:
派生自的每个控件
TOleControl
都有潜在的焦点问题。为了避免包含允许测试类的OleCtrls单元(其中将包含Variants ),该接口用于测试,这是一个很好的指标。
TOleControl
IOleClientSite
TOleControl
从完整的片段:
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
Bump 20110515(12 个月后)
Bump 20150401(7 年后):在 XE6 中仍然不起作用
凹凸20210309(11年后)