Solved

PROBLEM: Lost a focus

Posted on 2004-09-30
13
421 Views
Last Modified: 2010-04-04
Hello All,

I have small problem...

I have a form with two elements, TWebBrowser and TEdit. When I show some information in TWebBrowser TEdit losts focus in any ways... I did so to fix this problem:
---
    if(edChatMess.CanFocus)then begin
      Self.ActiveControl:=edChatMess;
      edChatMess.SetFocus;
    end;
---

And sometimes I get same trouble...

Can somebody suggest me way to fix this trouble: I need that TEdit always has focus in any cases!

Thanks,
Dan
0
Comment
Question by:DanDaemon
[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
  • 4
  • 4
  • 3
  • +2
13 Comments
 
LVL 12

Expert Comment

by:esoftbg
ID: 12191941
Set by ObjectInspector:

  edChatMess.TabStop := True;

for all other controls:

  ContolName.TabStop := False;

0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12191972
procedure TForm1.WebBrowserEnter(Sender: TObject);
begin
  edChatMess.SetFocus;
end;
0
 

Author Comment

by:DanDaemon
ID: 12191988
Hello All,

Please give me a constructive solutions.

2esoftbg, sorry but you gave me 'low skills' solutions.
Which will not solve my problem.

Thanks,
Dan
0
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!

 
LVL 12

Expert Comment

by:esoftbg
ID: 12192002
Use
  TSpeedButton  // does not get the focus
instead of TButton and TBitButton
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12192033
Sorry,
I just try to help ....
0
 

Author Comment

by:DanDaemon
ID: 12192170
2esoftbg,

NP... In example I described a very simple form, just for example... but in real application,
my form has many components and this components can have focus also, but when some
information is shown in TWebBrowser it means that TEdit should get focus...

Thanks,
Dan
0
 
LVL 31

Expert Comment

by:moorhouselondon
ID: 12194667
The hammer/egg approach would surely be to have coding in all of the relevant twebbrowser events which brings focus back to the tedit.

Where there is code already present in the onwhatever event then put the setfocus at the end of the custom coding.
0
 
LVL 31

Expert Comment

by:moorhouselondon
ID: 12194844
I see what you mean... error messages.
0
 

Author Comment

by:DanDaemon
ID: 12197982
Dear moorhouselondon,

Do you have sample code?

Thanks,
Dan
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 12198236
can you show the code on how you are "loading information in TWebBrowser"???

it might be as simple as:
try
  //load info into WebBrowser, whatever you are doing here
finally
  edChatMess.SetFocus;
end

if you want to get the focus back to WHATEVER control was focused before loading the data, you would do something like:

var
  aControl:TWinControl;
begin
  aControl:=ActiveControl; //grab the control that has the focus
  try
    WebBrowser1.Navigate('www.experts-exchange.com');
  finally
    ActiveControl:=aControl //return the focus to whatever control had the focus
  end
end;
0
 

Author Comment

by:DanDaemon
ID: 12198276
2BlackTigerX,

I was using same code, but it did not work properly when user clicks on TWebBrowser body.
After this click focus to TEdit does not work.

Thanks,
Dan

P.S. I want to know that somebody knows low-level WinAPI functions to set focus. Need small example.
0
 
LVL 31

Accepted Solution

by:
moorhouselondon earned 250 total points
ID: 12198418
Exactly same idea as esoftbg's second post, just extending to the onnavigatecomplete2 event, but though an initial navigate works fine (you can load up a web page and edit receives focus), if you click further then (I've got rid of the errors) the web control retains focus.  Figuring that the browser was waiting for a click on a link I used a webbrowser stop call, followed by edit1.setfocus but that didn't work.

(The code is straight from the Delphi Help, with a couple of additions).

var
  CurDispatch: IDispatch; {save the interface globally }

procedure TForm1.WebBrowser1NavigateComplete2(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);

begin
  if CurDispatch = nil then
    CurDispatch := pDisp; { save for comparison }
end;

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);
begin
  if (pDisp = CurDispatch) then
  begin
    Beep; {the document is loaded, not just a frame }
    CurDispatch := nil; {clear the global variable }
    webbrowser1.Stop;
    edit1.SetFocus;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
webbrowser1.Navigate('www.ebay.co.uk');
end;


0
 
LVL 6

Expert Comment

by:pritaeas
ID: 12198797
Can't you use the WinAPI function SetFocus(hWnd) ? Seems to me that is what you want. See MSDN for details.
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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 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