The Visual FoxPro 6.0 Class Browser

Steven M. Black

September 1998

Summary: Describes the Microsoft® Visual FoxPro® version 6.0 Class Browser and how, combined with the Component Gallery, it can be an effective tool for a variety of development purposes. (9 printed pages)

Contents

Introduction
What Is the Visual FoxPro Class Browser?
What's New in Visual FoxPro 6.0
The Browser Interface
Class Management
Write Your Own Add-Ins
Appendix: Browser.dbf Structure
About the Author

Introduction

This article discusses the Visual FoxPro Class Browser. Together with the new Component Gallery, the Class Browser provides many useful ways to accomplish common development tasks. This document also discusses the open architecture and programmable hooks that these tools expose for customization purposes.

What Is the Visual FoxPro Class Browser?

The Class Browser is useful for a variety of development purposes, such as:

What's New in Visual FoxPro 6.0

Most changes to the Visual FoxPro 6.0 Class Browser enhance its usability.

Of course, the big change in the Class Browser is integration with the new Component Gallery.

The Browser Interface

Figure 1. The Class Browser interface

Here are a few things you should know about the Class Browser to increase your productivity with this tool.

Click this button to see the class code. If the output contains nested classes, the code won't execute. Right-click this button and see the class code in HTML format. The window that appears is actually an instance of your browser, wherein you can use the Shortcut menu to view or print the HTML for displaying the source.
Use this button to create a new class. This new class can be a subclass of the currently selected class, a subclass of any other class, or a subclass of a Visual FoxPro base class.
You can redefine classes in the Class Browser with this icon. In Visual FoxPro 6.0, you can redefine a class to that of a different base class. You are warned that you will lose some intrinsic methods and properties in the process.
When you open a Method Code window, this button (which floats in its own toolbar independent of the Class Browser) allows you to view the code hierarchy in parent class methods.

View more than class libraries

In the Class Browser Open dialog box, note the different types of files that are supported. Figure 2 shows the Open dialog box pointing to the Component Gallery directory, with the drop-down list expanded to show the types of files you can show in the Class Browser.

Figure 2. The Class Browser Open dialog box

You can open Visual FoxPro forms in the Class Browser, and many of the features, such as code generation, work as you might expect. This is very handy for sharing your code with other users via e-mail.

If you open a Visual FoxPro project file, all the class libraries in that project will be visible in a single view. This is great if your project contains hundreds of classes and you have no idea in which library a particular class belongs.

In the Class Browser you can open any .exe or COM files (for example, .ocx, .dll, or .tlb) and display their public interfaces. If Help is available, pressing the spacebar invokes it.

To add controls to a form or class

In the Class Browser, open the .vcx (class library) file containing the class of the object you want to add to the form, select the class, and then use the drag-and-drop operation to move the Class icon to the design surface.

Invoke the class of a selected item on a form

In the form or Class Designer, select a control. If you then invoke the Class Browser, the class and its class library will be displayed with the class for the selected control highlighted. This works with running forms too, except that it uses the control that has focus.

Class Management

Bewildered by many of the class management activities that you can do with the Class Browser? Then see the article, "Managing Classes with Visual FoxPro."

Write Your Own Add-Ins

Class Browser add-ins are a built-in way you can extend the Class Browser. Add-ins are useful because of the endless variety of things you can do with them. For example, you can write an add-in to recursively call the Class Browser's ExportCode( ) method to generate all the code for a particular class library. You can also create an add-in to modify how ExportCode( ) works, like run beautify.app as a post process to format the exported code just as you please.

All Class Browser events and methods contain hooks to accept add-ins, and add-ins can also be run independently of Class Browser events and methods. See "Creating Add-Ins for the Visual FoxPro Class Browser" for more information.

There you have it: a quick cafeteria-style tour of some of the neat things in the Visual FoxPro 6.0 Class Browser. Of course, you should also read the Visual FoxPro online Help for more details. These are great tools, and if you use Visual FoxPro every day it's likely that you could make much better use of them.

Appendix: Browser.dbf Structure

The Class Browser stores all its metadata in a table named Browser.dbf found in your HOME() directory. The Component Gallery also uses Browser.dbf to store its catalog-related information. Table 1 provides a field-by-field description of important elements in Browser.dbf.

Table 1. Browser.dbf Metadata

Field Values Description B G
PLATFORM WINDOWS
<EMPTY>
Applies to records NOT of TYPE="ADDIN."
Applies only to records of TYPE="ADDIN."
TYPE PREFW

ADDIN
Specifies that the record stores browser and gallery preferences.
Specifies that the record stores add-in information.
ID FORMINFO


BROWSER


METHOD


MENU
Specifies that a Class Browser record stores form preferences; specifies that Gallery record stores catalog information.
Specifies that record contains default settings for the Class Browser. See the PROPERTIES field.
Specifies that the record contains a Class Browser add-in that is tied to a particular event or method.
Specifies that the record stores a Class Browser add-in that is NOT tied to a particular event or method, and is thus available on the Add-in menu.















DEFAULT .T.
.F.
Specifies a Component Gallery catalog.
Specifies a Class Browser record. The default is false (.F.).
 
GLOBAL .T.
.F.
Specifies that a gallery catalog is global.  The default is false (.F.)
BACKUP .F.
.T.
Specifies whether a backup is attempted the next time the file is opened. The default is false (.F.).

When you open a catalog or a .vcx file in the Class Browser or Component Gallery, this field in the associated browser.dbf record is queried. If the value is logical .T. (true), a search is made for a file of the same name in the backup subfolder. If the backup file doesn't exist, one is automatically created in a subfolder called Backup. Then the BACKUP field is set to .F.

Through add-in hooks or with any program that opens and updates browser.dbf, you can set this field to force the Class Browser or Component Gallery to automatically back up a file or table the next time that file is opened, and only the next time.

This feature is used internally in one special case; when browser.dbf is first created after Visual FoxPro is installed, a new browser.dbf is created with the default catalogs (around 5 or so). The BACKUP field is set to .T. so that each catalog gets backed up the first time it is opened because Visual FoxPro does not install the associated backup catalog tables. Beyond that special function, it can be used at will by developers for their own purpose.

NAME cFilename A memo field that specifies the file name that relates to the current record. This value appears in the add-ins Shortcut menu if the add-in is NOT tied to an event or method.

In Class Browser records the file extension can be .vcx, .pjx, .scx, .ovx, .dll, .exe, .app, or others. In Component Gallery records the file extension is .dbf.

DESC cDescription A memo field that contains the description of the catalog referred to in the NAME field.  
METHOD cMethodName A memo field that specifies the method to which a Class Browser or Component Gallery add-in is tied. If the method field is equal to "*" the add-in will execute for all methods.
PROPERTIES memo A memo field that specifies the default settings.  
SCRIPT   Internal Gallery use only.  
PROGRAM cPRGFilename A memo field that contains the name of the program to be run by a .prg-based add-in.
CLASSLIB cClasslibName A memo field that contains the name of the class library to be used by a .vcx-based add-in.
CLASSNAME cClassName A memo field that contains the name of the class to be used by a .vcx-based add-in.
DISPMODE <n> Specifies the display mode of the class library.
1 = hierarchical
2 = alphabetic
 
TOP <nnn> A numeric field that specifies the stored top (y) coordinate for the Class Browser/Component Gallery form.
LEFT <nnn> A numeric field that specifies the stored left (x) coordinate for the Class Browser/Component Gallery form.
HEIGHT <nnn> A numeric field that specifies the stored height of the Class Browser/Component Gallery form.
WIDTH <nnn> A numeric field that specifies the stored width of the Class Browser/Component Gallery form.
HEIGHT1 <nnn> A numeric field that specifies the stored height of the class and member description panes in the Class Browser.  
HEIGHT2 <nnn> A numeric field that specifies the stored height of the item description pane in the Component Gallery.
WINDOWSTAT <n> A numeric field that specifies the characteristics of the Class Browser or Component Gallery window.
0 = Normal window
1 = Minimized window
2 = Maximized window
PROTECTED .F.
.T.
A logical field that specifies whether protected members are displayed. The default is false (.F.).  
EMPTY .F.
.T.
A logical field that specifies whether empty methods are to be displayed.
HIDDEN .F.
.T.
A logical field that specifies whether hidden members are to be displayed.
DESCBOXES .F.
.T.
A logical field that specifies whether description panes are to be displayed.
AUTOEXPAND .F.
.T.
A logical field that specifies whether hierarchical items in the treeview are to be automatically displayed expanded in the left-hand side pane.
PUSHPIN .F.
.T.
A logical field that specifies whether the display is always on top.
PCBROWSER .F.
.T.
A parent class toolbar flag. A logical field that specifies whether the toolbar is on for that file.   
VIEWMODE <n> A numeric field that specifies the mode of the Gallery listview. 
1. Large (standard) Icons
2. Small Icons
3. List
4. Report
FONTINFO cFontPref A memo field that contains the current display font preference.
FORMCOUNT <n> A numeric field that specifies the number of Class Browser instances running for the .vcx file.
UPDATED <DateTime> A datetime field that specifies when this record was last updated.
COMMENT   Unused
User1….4 Unused

About the Author

Steven specializes in developing multilingual, multisite, and other challenging software situations, including project turnarounds and cleanups. He is the creator of Steven Black's INTL Toolkit, a multilingual framework for FoxPro and Visual FoxPro. He's a regular speaker at Visual FoxPro conferences, and his contributions occasionally darken the pages of FoxPro books and magazines.

Steven can be reached via e-mail at steveb@stevenblack.com. His Web site is http://www.stevenblack.com.