Initializing the Environment

The first task that a main file or application object must accomplish is to set up your application's environment. The default Visual FoxPro development environment establishes certain values of SET commands and system variables when Visual FoxPro opens. However, these settings might not be the best environment for your application.

Tip   To see the default values of the Visual FoxPro development environment, start Visual FoxPro without a configuration file by typing VFP -C and then issue the DISPLAY STATUS command.

It is always a good idea to save the initial environment settings and set up a specific environment for your application in your setup code.

To capture commands for the current environment

  1. From the Tools menu, choose Options.
  2. Press Shift and select OK to display the environment SET commands in the Command window.
  3. From the Command window, copy and paste into your program.

In an environment specific to your application, you might want to include code to:

  • Initialize variables.
  • Establish a default path.
  • Open any needed databases, free tables, and indexes. If your application requires access to remote data, the initialization routine can also prompt the user for the necessary login information.
  • Reference external library and procedure files.

For example, if you wanted to test the default value of the SET TALK command, store the value, and set TALK to OFF for your application, you could place the following code in your setup procedure:

IF SET('TALK') = "ON"
   SET TALK OFF
   cTalkVal = "ON"
ELSE
   cTalkVal = "OFF"
ENDIF

It is usually a good idea to save default settings in public variables, in a custom class, or as properties of an application object so that you can restore these values when quitting the application.

SET TALK &cTalkVal

Displaying the Initial Interface

The initial user interface can be a menu, form, or any other user component. Often, an application will display a sign-on screen or logon dialog box before displaying the opening menu or form.

You can initiate the user interface in the main program by using a DO command to run a menu or a DO FORM command to run a form.

See Also

Setting the Starting Point | Controlling the Event Loop | Compiling an Application | Structuring a Program as a Main File | DISPLAY STATUS