Solved

OnEnter event never fires for edit box with TWebBrowser

Posted on 2002-05-19
6
1,164 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now