FoxPro at development and runtime


You do not want to be using the live data for development so you must switch between test and live data when you distribute your application. If you do this manually then there is the danger that one day you will forget. It's better to switch automatically.

The problem falls into two parts:
  • detecting the environment.
  • switching to a new data path.

Detecting the environment

I have used four techniques to determine whether or not the executable is running from within the development environment. Each has its advantages and drawbacks.
  1. Use the VERSION(2) function to determine which version of FoxPro is running. This returns 0 for RunTime, 1 for Standard, and 2 for Professional.
  2. Use the SYS(0) function to get the user's logon name. SYS(0) returns a string in the form user name#machine name so I use the AT() function to find the position of the hash then read all the characters to the left of that position. If the user name is 'GEOFFF' then I assume that this is me working in development mode. A simple approach that can give me debugging information in the runtime environment.
  3. Pass a parameter into the executable. Treat Main.Prg as though it were a procedure by starting with an LPARAMETERS statement and pass the parameter in by adding it to the command line in the desktop shortcut. Use the PCOUNT function early in Main.Prg to detect whether a parameter has been supplied. If there's no parameter, I must be in development mode. If there is a parameter I can either switch to a predetermined data directory or read the data path from the parameter.
  4. Use the FILE() function to look for an INI file in the same directory as the executable. As with the parameter method above, I can either use the existence of the file to indicate runtime mode or I can read the file and extract the path to the data directory.
Whichever technique I have used to detect the environment, I always set up a global flag so that I can use it throughout the application to set development options like SET ESCAPE ON.

Switching to a new path

You can either use the SET PATH command to tell FoxPro where to find its data files or build a fully-pathed name for each file explicitly. I prefer to use the SET PATH technique because it will apply throughout the application.

There are two techniques to use with SET PATH. One is to name the data path explicitly:

IF m.glDevMode = .T.
  *-- Use the test files in the local Data folder
  SET PATH TO Data
ELSE
  *-- Use the data on network drive J
  SET PATH TO j:\LiveData
ENDIF

The other is to build (or read) the path as a string and use macro substitution:

SET PATH TO &lcDataPath

In both cases remember that you will have to add quotes around the path if it includes spaces.

Hints & tips

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox.
Autocomplete in VFP 9

Your Access database will look more impressive if you add custom toolbars...
Custom toolbars

FoxPro has always had functions to read and write files at a low level...
Foxpro low level file functions

More...
More pages of hints and tips for users of Microsoft FoxPro and Access databases.

Site Map