Solved

PROBLEM: Lost a focus

Posted on 2004-09-30
13
416 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending Gmail through Delphi 3 91
indy Tmemory stream non latin charcter issue 2 97
Delphi inherited method 6 61
Base1 Encode/Decode 3 67
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

919 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

11 Experts available now in Live!

Get 1:1 Help Now