Solved

OnEnter event never fires for edit box with TWebBrowser

Posted on 2002-05-19
6
1,181 Views
Last Modified: 2008-02-01
Hi,

I've noticed that when I click on the TWebBrowser then click on the edit box, the OnEnter event for the edit box doesn't fire.  To demonstrate, add a text box and a TWebBrowser to the form along with this code...

procedure TForm1.FormCreate(Sender: TObject);
begin
  WebBrowser1.OleObject.Navigate('www.google.com');
end;

procedure TForm1.Edit1Enter(Sender: TObject);
begin
  ShowMessage('OnEnter fired');
end;

Clicking on the TWebBrowser, then on the edit box gives the focus to the edit box, so the OnEnter event should fire but it doesn't.  Do you know of a work around for this?  I'm using Delphi 4 Pro.

Thanks in Advance,

Richard
0
Comment
Question by:Richard2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 8

Expert Comment

by:Cesario
ID: 7020041
Hello Richard,

The OnEnter Event will be fiered, if you select a Form Element form your Browser ( Edit, Button...)
If click the WebBrowser ( No Form ) so acitveControl is Edit1 not the webbrowser.

simply  add a label and timer to your form

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  label1.caption := (form1.ActiveControl).name;
end;


Best Regards

cesario
0
 

Author Comment

by:Richard2000
ID: 7022413
Hi,

Thanks for the code.  From the code you give it seems that according to Delphi, the WebBrowser never gets the focus.  Even though the WebBrowser is clicked on, the previous component (edit box) still seems to be regarded as having the focus.  In fact the OnEnter and OnExit events never seem to fire on the WebBrowser either.  Is there any way to ensure that when the WebBrowser is clicked on (or is tabbed to) it does get the focus properly?

Richard
0
 

Expert Comment

by:Farderlorn
ID: 7026362
At the moment, i don't know how to do, but what do you want to realize by setting the focus to TWebBrowser ? Could be you can go an other way.

Do you have to know if the user klicks on it? It's possible.

If you only want to remove the focus from the active component, it is possible, too.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Richard2000
ID: 7037462
Hi,

Thanks for your comment.  Setting the focus to the WebBrowser is sometimes important so that the user can use the keyboard shortcuts without having to click on the control.  The solution I have created is as follows...

procedure TMain.SetFocusToWebBrowser;
// Use this to set the focus to the WebBrowser because WebBrowser.SetFocus
// doesn't work and clicking on or tabbing to the control doesn't give it the
// focus (even though it appears to have it, Delphi does not change the focus).
// Always call this (in MessageHandler) when the user clicks on or tabs to the
// WebBrowser, so it behaves correctly as the focused control.

begin
  if WebBrowser = nil then Exit;
  if WebBrowser.Document = nil then Exit;

  with WebBrowser.Application_ as IOleobject do
    DoVerb(OLEIVERB_UIACTIVATE, nil, WebBrowser, 0, Handle, GetClientRect);
end;

procedure TMain.FixWebBrowserFocus;
// Always call after a new window has been displayed because if the WebBrowser
// has the focus and control goes to another window, the WebBrowser won't work
// correctly as the focused control when the window becomes active again
// (arrow keys won't work etc.).  A call to FixWebBrowserFocus gives it the
// focus again to ensure that it continues to function correctly.

begin
  if ActiveControl = WebBrowser then SetFocusToWebBrowser;
end;

Richard
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9006036
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ and Refund

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9096833
Question is PAQ'd and points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question