Solved

OnEnter event never fires for edit box with TWebBrowser

Posted on 2002-05-19
6
1,178 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 354
Delphi - replicating a form 8 92
LAN or WAN ? 11 106
How to insert .png images to TClientDataSet .cds file? 2 71
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

756 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