Solved

PROBLEM: Lost a focus

Posted on 2004-09-30
13
415 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
  • 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

746 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

12 Experts available now in Live!

Get 1:1 Help Now