Freigeben über


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

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.

DO FORM STARTUP.SCX

Restoring the Original Environment

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. For example, if you saved the SET TALK setting into the public variable cTalkVal, issue the following command:

SET TALK &cTalkVal

Note   Variable names used with macro substitution should not contain the "m." prefix because the period assumes a variable concatenation and will produce a syntax error.

If you initialize the environment in a different program than the one in which you are restoring it — for example, if you initialize by calling one procedure, but restore the environment by calling another — be sure you can access the values you stored. For example, store the values to restore in public variables, custom classes, or as properties of an application object.

See Also

Setting the Starting Point | Controlling the Event Loop | Compiling an Application | Structuring a Program as a Main File | Optimizing Visual FoxPro Startup Speed | SET Command Overview | DISPLAY STATUS COMMAND