Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Edit control won't receive Focus

Posted on 1998-03-30
10
Medium Priority
?
295 Views
Last Modified: 2010-04-06
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.
0
Comment
Question by:bgold
[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
10 Comments
 

Expert Comment

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

Form1.FocusControl(Edit1)
0
 

Author Comment

by:bgold
ID: 1361100
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!
0
 

Expert Comment

by:phillipf
ID: 1361101
Try this to set focus.

form1.activeControl := edit1;


0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Expert Comment

by:paulsinn
ID: 1361102
Have you set the 'Tabstop' property to True?

0
 

Author Comment

by:bgold
ID: 1361103
So far, none of the "obvious" type answers have worked.  Setting the active control did not work either.
0
 

Expert Comment

by:BigMadDrongo
ID: 1361104
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
0
 
LVL 5

Expert Comment

by:inter
ID: 1361105
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

0
 

Author Comment

by:bgold
ID: 1361106
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?
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1361107
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
0
 
LVL 5

Accepted Solution

by:
inter earned 600 total points
ID: 1361108
Hi friends,
I have currenly no time to find the real cause but I promise it in few days. (Some kind of FINALS I have to pass)
The answer is to use:
PostMessage(Edit1.handle, wm_setfocus,0,0);
Regards,
Igor
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

636 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