Chapter 3: Configuring Visual FoxPro

After you install Visual FoxPro, you might want to customize your development environment. Environment settings include the main window title, default directory, project, editor, debugger and form tool options, temporary file storage, field mappings for drag and drop operations, and many other options.

You can configure Visual FoxPro either interactively or programmatically. You can also establish configuration settings that are loaded when you start Visual FoxPro. For information on optimizing your system once it is configured, see Chapter 4, Optimizing Your System. For information on optimizing your Visual FoxPro applications, see Chapter 15, Optimizing Applications in the Programmer’s Guide.

This chapter discusses:

Setting the Visual FoxPro Configuration

The Visual FoxPro configuration determines how your copy of Visual FoxPro looks and behaves. For example, you can establish the default locations for files used with Visual FoxPro, how your source code looks in an edit window, and the format of dates and times.

Changes you make to the Visual FoxPro configuration can be temporary (for the current session only) or permanent (they become the default settings the next time you start Visual FoxPro). If the settings are temporary, they are stored in memory and are discarded when you quit Visual FoxPro. If you make permanent settings, they are stored in the Windows registry. The registry is a database maintained by Windows that stores configuration information about the operating system, all Windows applications, OLE, and optional components such as ODBC. For example, the registry is where Windows stores the associations between file name extensions and applications, so that when you click a file name, Windows can launch or activate the appropriate application. Similarly, Visual FoxPro stores its application-specific configuration information in the registry.

For an example of how to do this, examine Registry.prg in the Visual Studio …\Samples\Vfp98\Classes directory, which contains numerous methods, based on Windows API calls, that allow you to manipulate the Windows registry.

When you start Visual FoxPro, the program reads the configuration information in the registry and sets the configuration according to those settings. After reading the registry, Visual FoxPro also checks for a configuration file, which is a text file, in which you can store configuration settings to override the defaults stored in the registry. After Visual FoxPro has started, you can make additional configuration settings using the Options dialog box or SET commands.

Setting configuration using the Windows registry, configuration file, and Options dialog box

Note The run-time version of Visual FoxPro does not read the Windows registry when starting up, as registry settings are designed primarily to configure the development environment. If you intend to distribute your Visual FoxPro applications using a run-time library, you can establish configuration settings in two ways: with a configuration file, or with a program that manipulates the Windows registry on the user’s computer.

Finally, Visual FoxPro also maintains a resource file, Foxuser.dbf, which stores information about the current state of the program when you quit. For example, the resource file contains information about the location and size of the command window, current keyboard macros, which toolbars are displayed, and so on. The Foxuser.dbf file is an ordinary Visual FoxPro table, which you can read and change as required by your application.

Setting the Environment Interactively

You can set configuration options interactively by using:

Working with the Options Dialog Box

To view and change environment settings, you can use the Options dialog box.

The Options dialog box

To display the Options dialog box

The Options dialog box has a series of tabs representing different categories of environment options, as shown in the following table. For details about options you can set using each tab, see the Options dialog box.

Tabs available in the Options dialog box

Use this tab To access these features
View Interface options, such as whether to display a status bar, clock, command results, or system messages.
General Data entry and programming options, such as setting the warning sound, whether to log compilation errors, whether to automatically fill new records, what navigation keys to use, what color palette to use, and whether to warn before overwriting files.
Data Table options, such as whether to use Rushmore optimization, whether to enforce uniqueness using indexes, the memo block size, the record counter interval for searches, and what locking options to use.
Remote Data Remote data access options, such as connection timeout values, the number of records to fetch at once, and how to use SQL for updates.
File Locations Locations for the default Visual FoxPro directory, where Help is stored, and where auxiliary files are stored.
Forms Form Designer options, such as the grid spacing, the scale units to use, the maximum design area, and what template classes to use.
Projects Project Manager options, such as whether to prompt for wizards, whether to run or modify files when double-clicking, and options for source control.
Controls Options for what visual class libraries and ActiveX controls to make available from the View Classes button on the Form Controls toolbar.
Regional Formats for dates, times, currency, and numbers.
Debug Debugger display and trace options, such as what font and color to use.
Syntax Coloring Font and color options for identifying elements of programs, such as comments and keywords.
Field Mapping Options for what controls to create when dragging tables or fields to a form from the Data Environment Designer, Database Designer, or Project Manager.

Saving Configuration Settings

You can save the settings you make in the Options dialog box for the current data session, or as default (permanent) settings for your copy of Visual FoxPro.

To save settings for the current session only

  1. In the Options dialog box, make setting choices.

  2. Choose OK.

When you save settings for the current session only, they remain in effect until you quit Visual FoxPro (or until you change them again). To save changes permanently, save them as default settings; this stores them in the Windows registry.

To save current settings as default settings

  1. In the Options dialog box, make setting changes.

  2. Choose Set As Default.

    Note The Set as Default button is disabled until you make a change to the current settings.

You can override default settings by issuing SET commands or by specifying a configuration file when you start Visual FoxPro. For details, see Setting Configuration Options at Startup later in this chapter.

Using the SET Command to Configure Visual FoxPro

Most options displayed on the tabs in the Options dialog box can also be modified programmatically by using a SET command or by assigning a value to a system variable. For example, to use a year-month-date format for dates, you can change the Date Format setting in the Regional tab of the Options dialog box, or you can use the SET DATE command:

SET DATE TO ANSI      && Sets format to yy.mm.dd

If you configure the environment using SET commands, the settings are in effect only for the current session of Visual FoxPro. When you quit the program, your settings are discarded, and you must reissue the SET commands. However, you can automate this process by issuing SET commands at startup or using a configuration file. For details, see Setting Configuration Options at Startup later in this chapter.

Tip You can also save a configuration made with SET commands by displaying the Options dialog box and saving your settings there. For details, see Saving Configuration Settings earlier in this chapter.

Changing Configuration Settings in the Windows Registry

You can make changes directly in the Windows registry to set the Visual FoxPro configuration.

Visual FoxPro configuration settings in the Windows registry

To change the Windows registry, use the Registry Editor, a utility provided with Windows.

Note Exercise caution when changing the Windows registry; changing the wrong registry entry or making an incorrect entry for a setting can introduce an error that prevents Visual FoxPro from starting or working properly.

To change configuration settings in the registry

  1. In Windows, start the Registry Editor.

  2. Navigate to this registry key in HKEY_CURRENT_USER:
    Software\Microsoft\VisualFoxPro\6.0\Options
    
  3. Double-click the name of the setting to change, and then enter a new value.

  4. Close the Registry Editor.

Your change will be in effect the next time you start Visual FoxPro.

You can also make changes to the registry by calling Windows APIs from a Visual FoxPro program.

Displaying Configuration Settings

When Visual FoxPro is running, you can verify environment settings by using the Options dialog box or the DISPLAY STATUS command, or by displaying the values of individual SET Commands.

To display multiple environment settings

To display individual environment settings

Note Because settings are valid only for the current data session, you must capture your settings and place them in a program or a form’s Init event code for every private data session.

To echo Options dialog box settings to the Command window

  1. In the Options dialog box, make setting choices.

  2. Hold down the SHIFT key and choose OK.

    The settings are echoed to the Command window.

  3. Copy the setting commands from the Command window.

Setting Configuration Options at Startup

In addition to making changes to the Visual FoxPro environment interactively, you can establish configuration settings when you first start the program. Doing so allows you to override default settings.

This section describes you how can:

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 use 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 would 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. For details about specifying a main file for an application, see Chapter 13, Compiling an Application, in the Programmer’s Guide.

For example, if your application begins by displaying a form, you can issue SET commands in the code for the Load or Init events of the form. If your application begins with a menu, you can add the SETUP commands by entering them in the menu’s Setup option. For details, see “Adding Setup Code to a Menu System” in Chapter 11, Designing Menus and Toolbars, in the Programmer’s Guide.

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.

 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:

 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 in the following locations (in order):

If the default configuration file is not found 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 later in this chapter.

Enter configuration settings using one of these methods:

To enter SET commands in a configuration file

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

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

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

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

 Starting Applications or Programs Automatically

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

To start applications from a configuration file

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

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

Using Command-Line Options When
Starting Visual FoxPro

In addition to using the SET command and a configuration file, you can specify startup options by including a command-line switch. For example, using command-line options, you can suppress the display of the Visual FoxPro sign-on screen or specify a non-default configuration file. The following table lists the command-line switches available in Visual FoxPro.

Command-line switches for Visual FoxPro

Switch Description
-A
Ignores the default configuration file and Windows registry settings.
-C<file>
Specifies a configuration file (including path if necessary) other than the default (Config.fpw).
-D<file>
Specifies a runtime .DLL file (including path if necessary) other than the default.
-L<file>
Specifies a resource file (including path if necessary) other than the default, which allows you to use Visual FoxPro in a language other than the current language specified by Windows.
-R
Refreshes the Windows registry with information about Visual FoxPro, such as associations for Visual FoxPro files.
-T
Suppresses the display of the Visual FoxPro sign-on screen (banner). For details, see Preventing Display of the Sign-On Screen later in this chapter.
/regserver
registers an OLE component.
/unregserver
Removes an OLE registry entry.
REGSVR32 <server.DLL>
Registers a .DLL component.
/u <server.DLL>
Removes a .dll component.

For more information, see Command-Line Switches.

If the command switch requires arguments such as a file name, do not put a space between the switch and the argument. Separate multiple options with single spaces. For example, to specify a configuration file, use a command such as:

C:\Vfp98\VFP6.EXE -CC:\MYAPP\MYAPP.FPW

Preventing Display of the Sign-On Screen

By default, when Visual FoxPro starts, it displays a sign-on screen that shows the Visual FoxPro logo, version number, and other information. If you prefer that users of your application not see this sign-on screen, you can prevent Visual FoxPro from displaying it.

To prevent the display of the sign-on screen

For example, use a command such as:

VFP6.EXE -T

Configuring Visual FoxPro Toolbars

Visual FoxPro includes the following customizable toolbars.

Tool Associated Toolbars Command
Database Designer Database CREATE DATABASE
Form Designer Form Controls

Form Designer

Color Palette

Layout

CREATE FORM
Print Preview Print Preview
Query Designer Query Designer CREATE QUERY
Report Designer Report Controls

Report Designer

Color Palette

Layout

CREATE REPORT

Activating and Deactivating Toolbars

By default, only the Standard toolbar is visible. When you use a Visual FoxPro designer tools (for example, the Form Designer), the designer displays the toolbars that you commonly need when working with that designer tool. However, you can activate a toolbar any time you require it.

To activate a toolbar

  1. From the View menu, select Toolbars.

  2. In the Toolbars dialog box, select the toolbar you want to activate.

To deactivate a toolbar

  1. From the View menu, select Toolbars.

  2. In the Toolbars dialog box, clear the toolbar you want to deactivate.

Customizing Existing Toolbars

The easiest way to create custom toolbars is by modifying the toolbars already provided with Visual FoxPro. You can:

You can also define custom toolbars by creating a custom toolbar class using code. For details, see Chapter 11, Designing Menus and Toolbars in the Programmer’s Guide.

Modifying an Existing Visual FoxPro Toolbar

You can modify any of the toolbars provided with Visual FoxPro. For example, you might want to remove a button from an existing toolbar, or copy buttons from one toolbar to another.

To modify a Visual FoxPro toolbar

  1. From the View menu, choose Toolbars.

  2. Select the toolbar you want to customize and choose Customize.

  3. Remove buttons from the toolbar by dragging them off of the toolbar.

  4. Add buttons to the toolbar by selecting an appropriate category in the Customize Toolbar dialog box and then dragging the appropriate buttons onto the toolbar.

  5. Complete the toolbar by choosing Close in the Customize Toolbar dialog box and then closing the toolbar window.

Tip If you change a Visual FoxPro toolbar, you can restore it to its original configuration of buttons by selecting the toolbar in the Toolbar dialog box and then choosing Reset.

Creating a New Toolbar from Existing Toolbars

You can create your own toolbars comprised of buttons from other toolbars.

To create your own toolbar

  1. From the View menu, choose Toolbars.

  2. Choose New.

  3. In the New Toolbar dialog box, name the toolbar.

  4. Add buttons to the toolbar by selecting a category in the Customize Toolbar dialog box and then dragging the appropriate buttons onto the toolbar.

  5. You can rearrange buttons on the toolbar by dragging them to the desired position.

  6. Complete the toolbar by choosing Close in the Customize Toolbar dialog box and then closing the toolbar window.

Note You cannot reset buttons on a toolbar you create.

To delete a toolbar you created

  1. From the View menu, choose Toolbars.

  2. Select the toolbar you want to delete.

  3. Choose Delete.

  4. Choose OK to confirm the deletion.

Note You cannot delete toolbars provided by Visual FoxPro.

Setting Editor Options

You can configure the Visual FoxPro editor to display text the way you want by setting the font and text alignment. You can also make the editor easier to use by setting your preferences for indentation, wordwrap, automatic backup copies, and other features.

To configure the editor, use the Edit Properties dialog box.

The Edit Properties dialog box

For details about editor settings, see Edit Properties dialog box.

To display the Edit Properties dialog box

  1. Open an editor window in one of these ways:
  2. Right-click anywhere in the editor window to display the shortcut menu, and then choose Properties.

Tip You can display the Font dialog box directly by right-clicking the edit window and then choosing Font from the shortcut menu.

By default, settings that you make in the Edit Properties dialog box apply only to the current edit window. For example, if you change the font, the font for all text in the current window is changed. If you open another edit window, or if you close the current file and then reopen it, the default settings apply.

If you prefer, you can save your settings permanently, or so that they apply to all files of a similar type. If you apply options to similar file types, Visual FoxPro uses the settings you make when you edit files with the same extension (for example, all .prg files, or all method code in the Form Designer).

To save editor options permanently

To apply editor options to similar files

You can also set the color and font that the editor uses to identify keywords, comments, and other elements of programs. For details, see Syntax Coloring Tab, Options dialog box.

Restoring the Visual FoxPro Environment

If you want to close down all operations and return Visual FoxPro to its state at startup, issue the following commands, in the following order, in the Command window or in a program called just before you quit Visual FoxPro.

CLEAR ALL
CLOSE ALL
CLEAR PROGRAM

CLEAR ALL removes all objects from memory which, in turn, closes all private data sessions and cursors.

CLOSE ALL, after CLEAR ALL has completed successfully, closes all databases, tables, and cursors in data session 1, the default Visual FoxPro data session.

CLEAR PROGRAM clears the compiled program buffer of the most recently executed programs. CLEAR PROGRAM forces Visual FoxPro to read the programs from disk, rather than from the program buffer.

Cleaning Up During Transactions If transactions are in progress, use the END TRANSACTION command for each level of transaction before issuing CLEAR ALL, CLOSE ALL, and CLEAR PROGRAM.

Cleaning Up During Buffered Updates If buffered updates are in progress, use either the TABLEUPDATE( ) or TABLEREVERT( ) functions for each cursor with buffered updates before issuing CLEAR ALL, CLOSE ALL, and CLEAR PROGRAM.