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.
HOME()
, Sys(2004), FullNameUntil VFP 6, the two functions here were identical. With no parameters (or no additional parameters for SYS(2004)), they both return the directory from which Visual FoxPro was started. Obviously, the mnemonic HOME()
is a better choice than the mysterious SYS(2004) (despite the fact that SYS(2004) is burned in our brains). VFP 6 added a number of alternate uses for HOME()
to let us find various other directories, and VFP 7 added yet another.
FullName, a property of the VFP Application Object
, is the Automation Server version of the same information—it gives you both the full path to the directory and the name of the executable that started the VFP session in question.
cHomeDirectory = HOME( [ nWhichDir ] )
cHomeDirectory = SYS( 2004 )
cStartingEXE = appApplication.FullName
Parameter |
Value |
Meaning |
nWhichDir |
Omitted |
Return the directory from which VFP was started. For the development environment, this is the location of VFP.EXE; for a runtime application, it's the location of the runtime files. |
1 |
Return the root directory of the VFP directory tree—in other words, the directory into which VFP was installed. |
|
2 |
Return the directory to which the VFP samples were installed. Same as _SAMPLES. |
|
3 |
Return the Common subdirectory of the Visual Studio installation. |
|
4 |
In VFP 6, return the Common\Graphics subdirectory of the Visual Studio installation. In VFP 7 and later, return the Graphics directory of the VFP installation. |
|
5 |
Return the samples directory of the Visual Studio/MSDN installation. |
|
6 |
Return the Common\Tools directory of the Visual Studio installation. |
|
7 |
Return the "user application data" directory—that is, the directory where Windows thinks it should store data for the application. In Windows 2000, this is, by default, C:\Documents and Settings\<user name>\Application Data\Microsoft\Visual FoxPro\. This was added in VFP 7. |
First, be aware that HOME()
and SYS(2004) always include the final backslash. (So does FullName, but that’s because it’s separating the path from the filename.)
Many of us have gotten in the habit of assuming that HOME()
and SYS(2004) always refer to the main FoxPro directory. We shouldn’t have. The functions actually return the directory containing the necessary Visual FoxPro libraries. When you run an EXE from outside Visual FoxPro, this is the directory containing the various support libraries. Most often, that directory is the Windows system directory, not the one containing our EXE file. On the whole, this means we’re using these functions a lot less than we did in FoxPro 2.x.
To find the directory containing your application, you’ll have to parse SYS(16,1) to find everything before the last backslash. See the example below.
FullName is a property of the VFP Application Object
. It tells you both the full path to the instance of VFP that’s running and the name of the executable that’s operating as a server. Since the Application Object
also has a Version property, we suspect we’re far more likely to just grab the path here than to try to figure out which version is running by looking at the EXE name.
The VFP 6 additions to HOME()
make it easier to write code that uses the various common elements provided with Visual Studio and, for that matter, to write about those common elements or find them during development. It also makes the development team’s job easier because they no longer have to worry about moving things around. We just have to remember to write our code using the various permutations of HOME()
rather than assuming, for example, that the VFP samples are always in a \SAMPLES subdirectory or that bitmaps are in a \GOODIES\GRAPHICS\BITMAPS directory. Since HOME(2) or HOME(4) is shorter anyway, we’re happy.
Having said that, the removal of VFP 7 from Visual Studio appears to have rendered a couple of these items useless. In VFP 6, HOME(3), HOME(5) and HOME(6) return the values indicated in the table above. In VFP 7, all three return the empty string, even with Visual Studio 6 installed. Since none of us have the prerelease of Visual Studio .NET installed on our production machines, we’re not sure what happens when it’s installed, but we expect that it won’t change anything in this regard.
VFP 7 added one more useful item here. Increasingly, Microsoft wants you to store application data in a directory tree of its choosing. In some versions, it’s a set of folders under Profiles. In others, it’s the Documents and Settings tree. (Personally, we think Microsoft should stop telling us where to put our data, and even more, should stop propagating directories with spaces in their names. Unfortunately, they didn’t ask us.) In VFP 7, this directory contains files like the resource file (FoxUser.DBF), the tables for IntelliSense (FoxCode.DBF) and the Task List (FoxTask.DBF), and the Command Window history (_Command.PRG). HOME(7) gives you an easy way to find this directory so you can store or retrieve files there.
WAIT WINDOW "Support files are in " + HOME()
WAIT WINDOW "This app is running from " + ;
JustPath(SYS(16,1))
* Find out about the application object in the current session
* though it's far more likely you'll be doing this in another
* Automation client.
? _VFP.FullName
* Use a bitmap file.
_SCREEN.Picture = HOME(4)+"BITMAPS\ASSORTED\BALLOON.BMP"
Application, Configuration Files, _FoxCode, _FoxTask, FoxTools, JustPath(), _Samples, Sys(16), Version, _VFP