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.
VARREAD()
These two identical functions tell you the name of the current field in a READ or Browse. In a Visual FoxPro form, they return the ControlSource of the current control, but without any of the container hierarchy that identifies it.
cCurrentField = SYS(18)
cCurrentField = VARREAD()
In a FoxPro 2.x-style READ and a Browse, VARREAD()
is handy for finding out where the cursor is sitting, so you can act on that field. (We much prefer the mnemonic VARREAD()
to the cryptic SYS(18).) A common use of VARREAD()
in 2.x apps was to provide context-sensitive help (ON KEY
LABEL F1 DO GetHelp WITH VARREAD()
).
In Visual FoxPro, the ActiveControl property of a form gives much broader access to the information, since you can use it to check information about any property of the current control. (Unfortunately, ActiveControl isn’t always available.)
In READ and forms, the field/control name is returned in uppercase. In Browse in FoxPro 2.x, the field name returned had the first letter in uppercase and the rest in lowercase. This made it easy for a routine to tell whether it was called by a Browse or a form/screen. However, in VFP, the name is always returned in uppercase, even in a Browse. This makes sense because Browse is really a grid.
In a form, the value returned by VARREAD()
and SYS(18) contains just the ControlSource of the current object; it doesn’t contain a complete path to the ControlSource. If the ControlSource is a property of some object, the name alone doesn’t do you much good.
In new forms, we recommend using the OOP way whenever possible and leaving VARREAD()
for Browse code. As for SYS(18), don’t ever use it—it’s unreadable.
* To see what the current field is in a Browse
ON KEY LABEL F2 WAIT WINDOW VARREAD()
USE Customer
BROWSE
* Now move around and press F2