Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

OnEnter event never fires for edit box with TWebBrowser

Posted on 2002-05-19
6
Medium Priority
?
1,197 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Hire Technology Freelancers with Gigs

Work with 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.

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…
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

721 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