Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem on SetFocus

Status
Not open for further replies.

hdc

Programmer
Mar 25, 2002
12
0
0
HK
I am using VFP 3.0. There is a long time trouble for me. When I want to shift the focus to something like a ComboBox, I find the focus frequently jumps to the object following the target I intend to set. For examples, the sequence of object in TAB is A>B>C>D>E. If I issue B.SetFocus, sometimes (not always) the focus jumps to C. Is this a bug in VFP 3.0 or am I doing something wrong?
 
It's been a long time since I used VFP 3.0 (you are using 3.0b aren't you?), but a lot depends on WHERE you are doing the setfocus(). If you are setting it from a method that normally sets the focus somewhere (e.g. LostFocus()) then you should include a NODEFAULT to prevent any "focus" confusion.

Rick
 
Rick,
Thank you for your reply. Yes I am using 3.0b.
The confusion happens almost everywhere (e.g., CLICK(), VALID()). I can't trace any pattern as it occurs sometimes but does not occur sometimes. It depends on what is done inside the CLICK() and VALID().
I don't get your meaning of NODEFAULT. Where should I include it?

Hetzer
 
Hetzer,
First, if you ever plan on upgrading to VFP 5/6/7, you'll want to move any setfocus() code from your valid() to your lostfocus() methods (it's no longer 'legal' to do this inside a valid or when - anywhere in the call stack!).
For Example in a Lostfocus():

DODEFAULT && cover any dependent class code
....
IF condition
thisform.cboMyCombo.setfocus()
NODEFAULT && refers to this control's normal 'movement'
RETURN
ENDIF
....

This way instead of the normal moving of focus to the next control, it'll just go to your combobox.

Rick
 
OOPs, after having some lunch, I realized VFP 3.0 didn't have DODEFAULT, so if you needed it, it would probably look like:

This.ParentClass::LostFocus()

For more info on NODEFAULT, see the help file topic on DEFINE CLASS.

Rick
 
Rick,
Thank you again. I have tried adding a NODEFAULT and moving the object_new.SetFocus to object_old.LostFocus(). The problem is fixed.
Just for curiosity: I have read the Language Reference of DEFINE CLASS and found NODEFAULT. Its function should be to avoid VFP to do its default event or method when VFP is doing an event or method. Do you mean that VFP3.0 will run a default SetFocus when it processes a VALID()? Therefore the SetFocus previously issued in the VALID() is overriden. However how can VFP decide the default object that it should focus to? It is neither the first nor the last object that the focus jumped to.

Hetzer
 
Hetzer,
When you "leave" a field, it goes to the one that has the next highest available TabIndex value (assumes control's TabStop is .T. and Visible is .T.). The tab order is set based on the order you add the controls on the form. You can change the tab order - I'm not sure of the options in 3.0, but in 5.0 -> 7.0, with a form (or class) open, Menu -> View -> Tab Order. The presentation can be changed in the Menu -> Tools... -> Options -> Forms (tab) -> Tab Ordering. 'Interactive' shows the tab numbers on the form, and 'By List' shows them much like FPW did.

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top