Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

OBJNUM(), OBJVAR(), _CurObj

Here’s another batch of stuff that was crucial in FoxPro 2.x and is obsolete in Visual FoxPro. In FoxPro 2.x, each item (@ … GET or @ … EDIT) on a screen was assigned a unique “object number.” Within button groups, each button received its own number. These two functions and one system memory variable operated on those object numbers.

OBJNUM() takes a variable listed in @ … GET or @ … EDIT and returns its object number. OBJVAR() (added in version 2.6) takes an object number and returns the name of the variable associated with it. _CUROBJ controls the focus—it contains the number of the object with focus. Changing _CUROBJ changes the focus.

Visual FoxPro has alternative ways to accomplish these tasks, and the object-number system is only partly there. Visual FoxPro forms don’t use it. Forms that include any @ … GETs or @ … EDITs do, but OBJNUM() and OBJVAR() don’t recognize any Visual FoxPro controls on the form, only the GETs and EDITs.

The bottom line is: don’t mix and match. Use Visual FoxPro’s new form methodology. Refer to objects on the screen by their object hierarchy (Form.Page frame.Page.Object) rather than a number, and move focus to the desired object by calling its SetFocus method. If you can’t do this for some reason, then stick completely with the old @-based system.

See Also

@ Commands, ActiveControl, SetFocus, This