Solved

OnEnter event never fires for edit box with TWebBrowser

Posted on 2002-05-19
6
1,172 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
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 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