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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining what has focus

Status
Not open for further replies.

fmoore0001

Programmer
Dec 3, 2002
192
US
I have a piece of code where a value can make the focus move to a grid. But, then I need to know if the GRID itself did get focus to do some other routines. How can I determine if a grid has the focus?

Frank
 
Barbara, I tried it. Does not return a value for the object name.

frank
 
Yes, it does:

test = _screen.activeform.name
WAIT TYPE("test") WINDOW
WAIT "Len of Test is " + STR(test, 10, 0) WINDOW
WAIT test WINDOW

test returns a value

test = _screen.activeform.activecontrol.name
WAIT TYPE("test") WINDOW
WAIT "Len of Test is " + STR(test, 10, 0) WINDOW
WAIT test WINDOW

test does not return a value.

And my goal is to know the name of the active control on a form.

Frank
 
This doesn't make any sense. Every object in VFP has a Name property, and it's character, not numeric. Your code should be blowing up when you try to do the STR() of test.


-BP (Barbara Peisch)
 
Barbara,

You are right on the STR() statement. The corrected is:

test = _screen.activeform.activecontrol.name
WAIT TYPE("test") WINDOW
WAIT "Len of Test is " + STR(LEN(test), 10, 0) WINDOW
WAIT test WINDOW

and the results are:

U
0
"" (actually does not display)

I have tried _Screen.activecontrol.name
and THISFORM.activecontrol.name

and all report:

U
0
""

So I cannot figure what gives. I found some confirms (from you, in one) on doing it this way, but all were for Visual Basic. Try it yourself. I am using VFP7, SP1.

Frank
 
Oh, so you don't have a _Screen.ActiveForm then. (The type is "U".) You have a case where at the time you want to check what the active control is, there is no active control at all. You just need to check if the type of _screen.ActiveForm.ActiveControl.Name is "U", and if not, if it's the control you're looking for.


-BP (Barbara Peisch)
 
No, I needed the name. There are two controls, one a field, one a grid. a Keypress code may move to one control or the other, but I don't know which one it will be, so I want to detect the active control.

But, I have written code a dozen ways on forms, and this statement never seens to return a value.

Frank
 
But my point is that you have a situation where there is nothing that has focus. There is no active control in the situation you posted above. If you have an active control, then the name of that control will be in _screen.ActiveForm.ActiveControl.Name.


-BP (Barbara Peisch)
 
Barbara, you were absolutely right. A variation of your code:

THISFORM.lastcontrol = LOWER(THISFORM.ACTIVECONTROL.NAME)

gave me the correct last control every time IF I put this command in the LOSTFOCUS method. My little keyboard trap failed because by the time I tested (via the form KEYBOARD method) I was OFF the control, so you were right about this, too. Now, I move through LOSTFOCUS for the last control, save the value, and when it moves to the KEYBOARD method for the form I choose what to do next with no problems.

Thanks for all your help.

Frank
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top