Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TOleControl puts ActiveControl in wrong state?

22 views
Skip to first unread message

Ian Boyd

unread,
Apr 30, 2008, 9:53:40 AM4/30/08
to
"Non-VCL controls (like TWebBrowser), which do not use VCL mechanisms and
leave the ActiveControl property in the wrong state, cause trouble when the
control is refocused. Every control derived from TOleControl has potentially
the focus problem."
-Mike Lischke


In Mike Lischke's now defunct Virtual Treeview, there was workaround code
added to fix a bug, when using a TWebBrowser control on the same form.

The problem was that if the user tries to interact with the control, the
first mouse click is eaten. They have to click one to give the control
focus, then they can interact with the control.

He has comments to explain:

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;


Problem is that the workaround is no longer working for me. And to be honest
i have no idea what the problem was, and how his solution fixed it.

Is there anyone who reads his comments:

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

understand what he's talking about, could explain what the problem is, and
how what he's doing was supposed to fix it? The code is reaching the
intended "Form.ActiveControl := nil" statement, but it just isn't doing the
trick. i'd fix it, but i have no idea how he found it, how it can come about
that a TOleControl doesn't "use VCL mechanisms and leaves the ActiveControl
property in teh wrong state"


Note: Reposting this under a different subject and different opening
paragraph to trick people into reading it, even though the content is
identical to the previous post.


0 new messages