Partager via


Setting Configuration Options at Startup

You can establish configuration settings when you first start the program, which allows you to override default settings.

Using SET Commands

One way to establish configuration settings is to issue one or more SET commands when your application starts. For example, to configure your system to display a clock in the status bar when the application starts, you can issue this SET command:

SET CLOCK ON

The exact point at which you issue the SET command depends on your application. In general, you issue SET commands from your application's main program file, which is the program or form that controls access to the rest of your application. You can also issue SET commands from the Load or Init events of the form. If you are using private data sessions, it may be necessary to make these settings in the BeforeOpenTables Event of your DataEnvironment object. For details about specifying a main file for an application, see Compiling an Application.

If your application has a form set as main in the project manager, and it then launches a menu, you can add SETUP commands by entering them in the menu's Setup option. For details see Adding Setup Code to a Menu System in Designing Menus and Toolbars.

Tip   An efficient way to manage SET commands for startup is to create a procedure that contains all the commands that you want to issue. You can then call the procedure from the appropriate point in your application. Keeping all the SETUP commands in a single procedure makes it easier to debug and maintain your configuration settings. You can also put the code in the class on which your application object is based, or the class on which your forms are based.

Using a Configuration File

In addition to setting the Visual FoxPro environment using the Options dialog box or SET commands, you can establish preferred settings and save them in one or more configuration files. A Visual FoxPro configuration file is a text file in which you can specify values for SET commands, set system variables, and execute commands or call functions. Visual FoxPro reads the configuration file when starting up, establishing the settings and executing the commands in the file. Settings made in the configuration file override default settings made in the Options dialog box (and stored in the Windows registry).

Using a configuration file provides several advantages. You can:

  • Override the default settings established in the Options dialog box.
  • Maintain several different configuration files, each with different settings, so that Visual FoxPro can load a configuration suitable to a particular user or project.
  • Make changes more easily than if you establish settings with the SET commands in the program initialization sequence.
  • Start a program or call a function automatically when Visual FoxPro starts.

Creating a Configuration File

To create a configuration file, use the Visual FoxPro editor, or any editor that can create text files, to create a text file in the directory where Visual FoxPro is installed. Earlier versions of Visual FoxPro created the file Config.fpw in the startup directory. Config.fpw became the default configuration file. You can create any program file and use it to establish default settings and behaviors by starting Visual FoxPro using that file either by double clicking the file or using a command line reference.

If you are creating a new configuration file, you can save it using any name you want. By convention, configuration files have the extension .fpw.

When you start Visual FoxPro, you can use a default configuration file from the following locations in order:

  • Current working directory
  • Directory where Visual FoxPro is installed
  • Directories listed in the DOS path

If Visual FoxPro does not find a configuration file in these locations, Visual FoxPro uses only the default settings established in the Options dialog box.

Note   For details about specifying an alternative to the default file name or location for the configuration file, see Specifying the Configuration File to Use.

Enter configuration settings using one of these methods:

  • Make settings with the SET command.
  • Set system variables.
  • Call programs or functions.
  • Include special terms used only in configuration files.

To enter SET commands in a configuration file

  • Enter SET commands without the SET keyword and with an equal sign.

    For example, to set a default path type, use this format:

    DEFAULT = HOME()+"\VFP"
    

    To add a clock to the status bar, use this command:

    CLOCK = ON
    

To enter a setting for a system variable, use the same syntax you would use in the Command window or in a program.

To set system variables in a configuration file

  • Enter the name of the system variable, an equal sign (=), and the value to set the variable to.

    For example, the following command specifies an alternative spell-checking program:

    _SPELLCHK = "SPLLCHK.EXE"
    

You can also call functions or execute programs from within a configuration file by using the COMMAND command. For example, you can start an initialization program as part of the startup process.

To call functions or execute commands in a configuration file

  • Enter COMMAND, an equal sign (=), and the command to execute or function to call.

    For example, to include the Visual FoxPro version number in the caption of the main Visual FoxPro window, use this command:

    COMMAND =_SCREEN.Caption="Visual FoxPro " + VERS(4)
    

    The following command launches a specific application when Visual FoxPro starts:

    COMMAND = DO MYAPP.APP
    

You can also use special terms in a configuration file that do not correspond to SET value, system variables, or commands.

To use special terms in a configuration file

  • Enter the special term, an equal sign (=), and the setting.

    For example, to set the maximum number of variables available in Visual FoxPro, use this command:

    MVCOUNT = 2048
    

For a complete list of special terms for configuration files, see Special Terms for Configuration Files.

Specifying an External Configuration File

You can use an external configuration file in addition to an internal configuration file in circumstances where you need to configure settings separately. For example, setting SCREEN=OFF should be performed in an internal configuration file.

You can set Visual FoxPro to read an external configuration file following an internal configuration file by using the new ALLOWEXTERNAL directive in the internal configuration file. When you include the setting ALLOWEXTERNAL=ON in the internal configuration file, Visual FoxPro searches for an external configuration file, usually Config.fpw, and reads its settings. You can also specify a different configuration file using the -C command-line switch when starting Visual FoxPro.

Note   For .exe and .dll file servers, Visual FoxPro supports only those configuration files bound inside the server. Therefore, Visual FoxPro disregards the ALLOWEXTERNAL setting.

To read an external configuration file after an internal one

  1. In the internal configuration file, set the special term ALLOWEXTERNAL to on.

    ALLOWEXTERNAL = ON
    
  2. When you start your program, either specify a second configuration file using the -C command-line switch or have a second configuration file in the default program path.

For more information about command-line switches, see Using Command-Line Options When Starting Visual FoxPro.

The settings in an external configuration file take precedence over those in the internal configuration file, if duplicate settings exist, because the external configuration file is read after the internal file. Visual FoxPro does not begin initialization until it reads both files.

If you want to specify the configuration file as read-only, place the file in your project and mark it as Included. If you want to specify that the file can be modified, place the file in your project and mark it as Excluded. You can then distribute the file separately with your application or executable file. By convention, configuration files use the .fpw extension.

Starting Applications or Programs Automatically

You can insert commands into a configuration file that automatically launches programs when Visual FoxPro starts. You can use these commands either to start an entire application or to start just a program, such as one that initializes system variables.

To start applications from a configuration file

  • Assign the name of your application to the _STARTUP System Variable anywhere in the configuration file:

    _STARTUP = MYAPP.APP
    

    -or-

  • Use the COMMAND command, which must be the last line in your configuration file:

    COMMAND = DO MYAPP.APP
    

Specifying the Configuration File to Use

When Visual FoxPro starts, you can specify a configuration file or bypass all configuration files, allowing Visual FoxPro to use its default settings.

When Visual FoxPro loads a configuration file, the settings in that file take precedence over corresponding default settings made in the Options dialog box.

To specify a configuration file

  • In the command line that starts Visual FoxPro, specify the -C switch and the name of the configuration file that you want to use (including a path if necessary). Do not put a space between the switch and the file name.

    -or-

  • In Windows, double-click the name of the configuration file to use. Visual FoxPro will start using the configuration file you have selected.

If you want to avoid using any configuration file, including the default file Config.fpw, you can suppress all configuration files. This causes Visual FoxPro to use only the default settings established in the Options dialog box.

To suppress a configuration file

  • In the command line that starts Visual FoxPro, add the -C switch with nothing after it.

    For example, to avoid any configuration file found in the startup directory or the system path, use this command line:

    Vfp8.exe -C
    

See Also

Visual FoxPro Environment Settings | Using Command-Line Options When Starting Visual FoxPro | Compiling an Application | Adding Setup Code to a Menu System | Designing Menus and Toolbars | Special Terms for Configuration Files | _STARTUP System Variable