ActiveForm, ActiveControl
When it comes to debugging, these may the two most important properties around. They give you a hook into whatever's going on at the moment. Both provide object references. ActiveForm points you to the form that contains the focus in a formset, or even just the form with focus without regard to formsets. ActiveControl points you to the control that has focus on a form.
Usage |
frmCurrentForm = frsFormSet.ActiveForm frmCurrentForm = _SCREEN.ActiveForm oCurrentControl = frmForm.ActiveControl |
Utterly annoying, however, is that when you switch focus to the Debugger, ActiveControl no longer works. Even if the Debugger is sitting in its own frame. Since even our humongous monitors make it hard for us to position both VFP and the Debugger so that each is fully visible, this is truly a pain. Now that we have a really good debugger, among the things this complicates is drilling down into the control with focus. We have to go to the form level, find the right control (but how do we know which one it is when ActiveControl no longer tells us!), and start from there. |
When the focus is in a grid, ActiveControl always points to the grid rather than to the individual control within the grid, which actually has focus. Thanks to our friend Drew Speedie, we have a way to climb down the containment hierarchy and find out which control is really in control here, but it ain't pretty: local loControl, lcActiveControl, lcJunk loControl = _SCREEN.ActiveForm.ActiveControl IF UPPER(ALLTRIM(loControl.BaseClass)) = "GRID" FOR i = 1 TO loControl.ColumnCount IF loControl.Columns[i].ColumnOrder = loControl.ActiveColumn * Name of the real ActiveControl: lcActiveControl = loControl.Columns[i].CurrentControl * Object reference to ActiveColumn: loControl = loControl.Columns[i] * Text string representing ActiveControl reference: lcJunk = "loControl." + lcActiveControl * Object reference to the real ActiveControl: loControl = &lcJunk EXIT ENDIF ENDFOR ENDIF |
Example |
* With a form running, you can change its * title from the Command Window like this: _SCREEN.ActiveForm.Caption = "Look what I can do!" * To see the name of the control with focus: ? _SCREEN.ActiveForm.ActiveControl.Name * To call a method of the active form from * a button on a toolbar, put something like this * in the button's Click: _SCREEN.ActiveForm.Save() |
See Also |