Guidelines for Using Visual FoxPro Foundation Classes

See Also

The Visual FoxPro .vcx visual class libraries located in the \Ffc\ folder contain a variety of foundation classes for enhancing your Visual FoxPro applications with little or no programming. You can freely distribute the foundation classes with your applications. These foundation classes are contained in the Component Gallery. The Component Gallery provides a quick and easy way to learn more about the properties, events, and methods of each of the foundation classes.

You can also open up a foundation class in the Class Designer or Class Browser to see its structure and code. This is a great way to learn how the foundation class works as well as offering excellent insights into programming with Visual FoxPro.

The following guidelines provide information about how you can add the Visual FoxPro foundation classes to your applications.

Class Types

You need to know the Visual FoxPro base class of a foundation class before you can add the foundation class to your application. Certain foundation classes can be used only as visual objects on forms, while others are non-visual and can be run programmatically without being placed on a form. The Visual FoxPro Foundation Classes documentation indicates the base class of each foundation class so you can determine if the foundation class can be added to a form, or run programmatically in your application. Note that in the Component Gallery you can right-click a foundation class to display a shortcut menu. Choose Properties from the shortcut menu, and then choose the Class tab to display the base class.

The following table lists the Visual FoxPro base classes and how they can be added to your applications.

Category A – base classes that can be dropped onto a form. Category B – base classes that can be dropped onto a form or run programmatically in your application. Category C – base classes that can only be run programmatically in your application.
Checkbox Custom Form
Combobox Container Formset
Commandbutton Timer Toolbar
Commandgroup ProjectHook  
Editbox ActiveDoc
Grid  
Hyperlink
Image
Label
Line
Listbox
OLE Control
Optionbutton
Optiongroup
Shape
Spinner
Textbox

Adding Foundation Classes to Forms

You will most often add foundation classes to forms. You can drag and drop foundation classes from the Component Gallery, Class Browser, Project Manager, and the Forms Control toolbar onto forms.

Note   You can select a foundation class you’ve added to a form and then choose Class Browser from the Tools menu to display more information about the foundation class.

Component Gallery – The Component Gallery provides the easiest way to add foundation classes to a form. For foundation classes with Category A and B base classes, you can drag the foundation class from the Component Gallery and then drop it on a form. You can also right-click a foundation class in the Component Gallery to display a shortcut menu, and then choose Add to Form to add the foundation class to the form.

Some of the foundation classes have associated builders that are automatically launched to prompt you for more information needed by the foundation class.

Class Browser – You can drag foundation classes with Category A and B base classes directly from the Class Browser to a form by using the drag icon in the upper left corner of the Class Browser. Select the foundation class in the Class Browser, click the icon for the foundation class in the upper left corner of the Class Browser, and then drag the icon over the form. Release the mouse button over the form where you’d like the foundation class to appear on the form.

Foundation classes dragged from the Class Browser to a form do not launch the associated builder. However, you can launch the builder after you drop the foundation class on the form. Select the foundation class on the form, then right-click to display the shortcut menu. Choose Builder from the shortcut menu to launch the builder.

Project Manager – Foundation classes with Category A and B base classes can be dragged from the Project Manager and dropped on a form.

Foundation classes dragged from the Project Manager to a form do not launch the associated builder. However, you can launch the builder after you drop the foundation class on the form. Select the foundation class, then right-click to display the shortcut menu. Choose Builder from the shortcut menu to launch the builder.

Form Controls toolbar – Foundation classes with Category A and B base classes added to the Form Controls toolbar can be added to a form.

If the Builder Lock isn’t on, foundation classes dropped from the Form Controls toolbar might launch an associated builder. If the Build Lock is on, you can launch the builder after you add the foundation class to the form. Select the foundation class on the form, and then right-click to display the shortcut menu. Choose Builder from the shortcut menu to launch the builder.

Adding Foundation Classes to Projects

When a form containing foundation classes is added to a Visual FoxPro project, the Project Manager automatically adds the visual class libraries containing the foundation classes to the project. However, there are other cases where you might need to add foundation classes to a project. For example, if your application runs a Category C foundation class, you must add the foundation class to the project.

You can add Visual FoxPro Foundation classes to a project by doing any of the following:

Adding Foundation Classes from the Component Gallery

You can drag a foundation class from the Component Gallery to a project, or you can right-click the foundation class in the Component Gallery to display a shortcut menu, and then choose Add to Project to add the foundation class to the project. When you add a foundation class to a project, the Add Class to Project dialog box is displayed, prompting you with the following options:

Add class to project

Choose this option to add the foundation class and its .vcx class library to the project. Again, this is done automatically for classes dropped onto a form (Categories A and B). For certain Category B and C classes where you plan to call them programmatically from within your application, you will want to choose this option.

Create a new class from selected class

Choose this option to create a new subclass from the foundation class you want to add to the project. This option allows you to enhance the functionality of the original foundation class, usually by adding additional program code.

Create a new form from selected class

Choose this option for foundation classes with a Form base class (for example, the foundation classes in _dialogs.vcx). This option allows you to create a new form from the foundation class and enhance the functionality of the original foundation class.

Adding Foundation Classes from the Windows Explorer

You can use Windows Explorer to access classes to add to your project.

To add a foundation class using Windows Explorer

The visual class library is added to the Class Libraries item in the Project Manager.

Adding Foundation Classes from within the Project Manager

You can use add classes to add to your project from within the Project Manager.

To add a foundation class from within the Project Manager

  1. In the Project Manager choose the Classes tab.

  2. Click the Add button.

  3. Select the class library from the \Ffc\ folder that contains the foundation class to add to the project.

  4. Click OK.

Incorporating Classes into your Application

In many situations, foundation classes don’t require additional programming to work with your application. However, you might need to provide additional program code for certain foundation classes (those of Category B and Category C non-visual base classes).

Non-Visual Foundation Classes

For example, foundation classes are often based on the Category B Custom class, and these require additional programming. These non-visual classes often perform common tasks such as checking information in the Windows registry, handling environment settings, managing application errors, and utilizing Automation with other applications, such as performing mail merge with Microsoft Word.

You can drop these non-visual classes onto a form, but you will need to do some additional work in order for them to work with your application. In some cases, a builder launches when you drag a foundation class onto a form.

The following example demonstrates program code to use a non-visual foundation class in your application:

  1. Drag the File Version foundation class from the Component Gallery (Foundation Classes\Utilities folder) onto a form.

  2. Add a command button to the form and add the following code to its Click event:
    WITH THISFORM._FILEVERSION1
    .cFileName = HOME( )+ 'VFP6.EXE'
    .GetVersion( )
    .DisplayVersion( )
    ENDWITH
    
  3. Run the form and click the command button.

You can incorporate a non-visual class in your application without dropping it on a form, as long as you include it in the project used to create the application. The following code illustrates how to run this same File Version foundation class when the class is not dropped onto a form.

LOCAL oFileVersion
oFileVersion = NewObject(_fileversion, _utilities.vcx)
WITH oFileVersion
.cFileName = HOME( )+ 'VFP6.EXE'
.GetVersion( )
.DisplayVersion( )
ENDWITH

Note  This example assumes that the code can locate the _utilities.vcx class library or from an .app file that is built containing _utilities.vcx.

When you use a non-visual foundation class, you need to know how and when the class is used within your application so it can be scoped correctly. If only a single form uses the class, you can just drag the class onto the form. However, if the class is used by many forms or is used globally by the application, the foundation class should have a global scope in the application so it remains accessible throughout the application. A global scope might also improve performance.

Visual Foundation Classes

You can also programmatically add visual foundation classes, such as those with form base classes, to your application. The following example shows code you can add to your application to display an Aboutbox dialog.

LOCAL oAbout
oAbout = NewObject(_aboutbox,_dialogs.vcx)
oAbout.Show( )

You can create a subclass of the dialog box foundation class for each of your applications so that you can customize the contents of the dialog box for each application. The following example demonstrates how you can subclass the Aboutbox foundation class:

  1. Drag and drop the Aboutbox class from the Component Gallery (Foundation Classes\Dialogs folder) to the project for your application.

  2. Select Create new form from selected class in the Add Class to Project dialog box that is displayed, and enter name for the form.

  3. Change the Caption property for the new form for your application.

  4. Save and close the form.

  5. Add program code (DO FORM FormName) to the procedure that runs the form, such as an About menu item procedure.

    -or-

Drag the Run Form button class from the Component Gallery (Foundation Classes\Buttons folder) onto the form. When the builder launches, you can specify the name of the form to execute.

If you use the Visual FoxPro 6.0 Application Framework, the Application Builder automatically handles adding forms (both .scx and .vcx form classes). The new Application Wizard or the Component Gallery New Application item installs this framework in projects they create. The Application Builder interacts directly with the framework and enables you to specify how and where the form is launched.

By using a framework built with the Application Wizard, the Application Builder, and Component Gallery, you have a rich set of tools for creating entire applications with minimal manual coding.

Class Naming Conventions

The Visual FoxPro Foundation classes and their properties and methods use the following naming conventions.

Classes and Class Libraries

Most foundation classes are subclassed from classes in the _base.vcx visual class library, which you can also find in the \Ffc\ folder. The naming conventions for these classes reflect the base class used. For example, a subclass of the Custom class is called _Custom in _base.vcx. All classes use an underscore ( _ ) to preface the name of a class in _base.vcx.

A few class libraries do not contain classes that are subclassed from _base.vcx because these classes are shared with other Visual FoxPro components such as wizards and builders. These classes are contained in class libraries without a preceding underscore, such as Registry.vcx.

Methods and Properties

Methods are often based on an action name such as RunForm. If the name contains several words, for example, RunForm, then capitalization reflects this. Properties are usually prefaced with a single lower case letter characterizing the data type of that particular property. For example, cFileName indicates that the property is of character type. In addition, default values for properties are also set to the appropriate data type. For example, a logical property can be initialized to false (.F.), while a numeric property can be initialized to 0.

Properties of classes that shipped in earlier versions of Visual FoxPro do not strictly adhere to these property naming conventions, and retain their earlier names to avoid compatibility conflicts with user code referencing these properties.

Enhancing or Modifying FoxPro Foundation Classes

You can enhance or modify the Visual FoxPro foundation classes to meet the needs of your application. However, we recommend that you do not modify the foundation classes themselves. The foundation classes might be periodically updated with new functionality.

Subclassing the Foundation Class

The source code is provided so you can subclass any foundation class to override or enhance properties and methods. Choose to subclass when the behavior of a particular foundation class varies between different applications.

Updating _base.vcx

If you want to add global changes to the Visual FoxPro foundation classes, you can modify _base.vcx. Since foundation classes are subclassed from _base.vcx, changes to this class library are automatically propagated to the foundation classes. A common set of methods and properties are provided for all the classes in _base.vcx. However, you can alter the classes in _base.vcx if they add desired behavior to your applications (unlike the foundation classes that we recommend that you do not change).

Instead of changing _base.vcx, however, you should redefine the classes in _base.vcx to inherit their behavior from your own custom base classes (rather than from the Visual FoxPro base classes currently used). If you already have a custom class library which subclasses the Visual FoxPro base classes, you can redefine the classes in _base.vcx to inherit from your custom classes so that when components use the _base classes they will inherit from your custom classes too. You can use the Class Browser to redefine the parent class for a particular class.

If you replace the entire _base.vcx class with your own, make sure that you have the same set of named classes, otherwise the foundation classes will have missing links.