Link to home
Start Free TrialLog in
Avatar of bgold
bgold

asked on

Edit control won't receive Focus

I'm beginning to think this problem is a Delphi problem....
A TBitBtn is pressed, the click event executes a function which does some various tasks, then it sets focus on an Edit control.  Well, the focus never really actually goes to the Edit control.  Why?  What can I do to fix this?

I have tried the following (keep in mind - No other processing/code occurs after the SetFocus.):
-Tested the currently ActiveControl and it actually shows the Edit control (but it still doesn't get focus).
-Executing ProcessMessages before and after the SetFocus.
-Setting focus to the form first, then the control.
-Re-showing the form and setting focus to the control.
Avatar of dotan
dotan

Try to set the focus to the edit control from the form by
using:

Form1.FocusControl(Edit1)
Avatar of bgold

ASKER

Unfortunately, your idea did not work.  I had also tried SetFocusedControl which also didn't work.  Why do you think the TBitBtn (on an MDI form, by the way) is not allowing focus to go from it to the child form control?  Other buttons work perfectly fine!
Try this to set focus.

form1.activeControl := edit1;


Have you set the 'Tabstop' property to True?

Avatar of bgold

ASKER

So far, none of the "obvious" type answers have worked.  Setting the active control did not work either.
If you send me your project to James_R_Bennett@SBPHRD.COM I'll have a look and see if I can make sense of why it's not recieving focus.

BigMadDrongo
Hi,
The thing you mentioned works fine when tested. Try to set the focus with the following:

PostMessage(Edit1.handle, wm_setfocus,0,0);
Regards,
Igor

Avatar of bgold

ASKER

Yes, Inter....that worked!!!  Finally!  If you resubmit it as an answer to my question, I'll award you the points.  By the way, do you have any explanation as to why that was the only thing that worked.  And just for kicks, why would a double-click event in a listbox not fire off?
You should always wrap focus calls around
  if WinControl.CanFocus then
    WinControl.SetFocus;

On to your first question...I would assume that you are doing something in your "function which does some various tasks".  From Danny Thorpe's book, Delphi Component Design..."WM_KillFocus Windows message has the special limitation that you should not cause a focus change while processing that message.  Failure to observe this will crash Windows."  So I would assume your doing something else to kick off a WM_KillFocus message to be processed, and Delphi will not let you move focus.  Now what your doing to kick off this message???

Rick Peterson
ASKER CERTIFIED SOLUTION
Avatar of inter
inter
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial