Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Articles
Search: 

Using The Visual FoxPro 8.0 ToolBox
Beth Massi, February 1, 2003
The Visual FoxPro Toolbox is a new enhancement to the VFP Integrated Development Environment (IDE) which aids in the Visual FoxPro Development experience. The Toolbox displays by category user customizable tool sets that the developer deems important for the creation of their applications. Too...
The Visual FoxPro Toolbox is a new enhancement to the VFP Integrated Development Environment (IDE) which aids in the Visual FoxPro Development experience. The Toolbox displays by category user customizable tool sets that the developer deems important for the creation of their applications. Tool sets typically consist of classes and components but as you will soon see, the Visual FoxPro Toolbox can contain much more than just components and classes and you can do much more than just drag-drop controls to the design surfaces.

The items in the tool sets can be drag-dropped like the current class toolbars, however, the items can also be common resources such as text, images, forms, programs, tables, etc., or other types like ActiveX controls, builders, or wizards that can be dragged onto the workspace, clicked to execute other default actions, or contain other behaviors accessible from the item shortcut menus. Because you have complete control over the Toolbox, it becomes an essential part of the IDE.

Like practically every feature in the Visual FoxPro IDE, the Toolbox is also extensible. So if a type of tool or behavior is not currently supported, you can add new behaviors and tool types without having to recompile the Toolbox application.

The individual tool sets are loaded into the Toolbox whose architecture also supports add-in tool sets, or categories. This way third party vendors or enterprise architects can easily provide their own specialized tool sets along with the class libraries, exposing only the concrete classes and hiding the complex abstract classes of their framework if they wish.

In this article I'll describe all the features of the Visual FoxPro 8.0 Toolbox and walk you through how to customize and add different types of supported tools to create and manage your own items and categories.

Starting the Toolbox

The Toolbox can be opened from the Visual FoxPro Tools menu or by clicking on the Toolbox icon located on the Visual FoxPro standard toolbar. When the Toolbox is opened for the first time it will prompt you to create the Toolbox data table which stores all the customized content for each user. This location defaults to a toolbox folder under the HOME(7) folder:

\Documents and Settings\UserName\Application Data\Microsoft\Visual FoxPro 8\Toolbox.

The Toolbox will create its content table files in this specified folder.

Figure 1. The Locate / Create Toolbox dialog is displayed the first time the Visual FoxPro Toolbox is started.

The location of an existing Toolbox table can be specified by selecting the appropriate option in the dialog. This gives an enterprise an opportunity to set up tool sets for their development teams ahead of time and distribute the Toolbox table files to their developers. Once the local data table is set up, the Toolbox will open onto the Visual FoxPro desktop.

Figure 2. The Visual FoxPro Toolbox

The Toolbox's tool sets are organized into categories. To open a tool set, click on one of the category buttons. The tool set is displayed in the middle of the Toolbox underneath its category button. If another category is open, the existing one is closed as the new category opens. If a tool set is larger than the visible category section, scroll arrows appear above and below the visible set of tools. Place your mouse over the arrows to continuously scroll the category. Click the arrows to uncover the next tool in the set. All item and category buttons are keyboard accessible by tabbing through the controls. If one is present, the mouse wheel can also be used to scroll through items in the category.

Default Toolbox Categories

The Visual FoxPro Toolbox ships with a default set of tools. These tool sets are contained in categories that you can customize. Some of these categories have special behaviors which will be explained in more detail when we discuss category types. When you first open the Toolbox, you will see the following categories:

Favorites - The Favorites category is a special category on the Toolbox. Here is where items that are used most often in a session can be stored. This category is meant to solve the problem of accessing tools from multiple categories quickly. Instead of switching from category to category to work with tools, one can add the item to the Favorites category by drag-dropping it onto the Favorites category button. This can also be achieved by right-clicking on the item and selecting Add to favorites from the shortcut menu. When items are placed in the Favorites category, they remain in their current category and a copy is created in Favorites.

Text Scraps - This category stores text scrap tools. Select and drag some text to this category to automatically create a text scrap tool. Text can be dragged to/from any Windows application that supports the drag-dropping of text.

VFP Base Classes - This category contains the Visual FoxPro base classes. This category is special in that you cannot permanently delete this category or any of the items in here.

VFP Foundation Classes - This category contains some of the more common or featured FoxPro Foundation Classes found in the FFC folder.

My Base Classes - This category contains the classes from _base.vcx class library found in the FFC folder.

My XML Web Services - This category displays all your registered XML Web Services. You can also register an XML Web Service directly from this category by clicking on the Register tool.

My ActiveX Controls - This category displays all of your loaded ActiveX controls. You specify these controls from the Visual FoxPro Tools menu under Options and selecting the Controls tab. For more information on loading controls, see the Visual FoxPro Help.

Toolbox Items

The items inside the categories represent many different types of objects. These objects can be classes from Visual FoxPro class libraries that are drag-dropped onto the workspaces like the IDE currently works with the form and class toolbars. This is how most of the items in the default categories work. For instance, if I drag a Label from the VFP Base Classes category to the form or class designer, a Label control will appear on the workspace that is of the Visual FoxPro base class Label. If I drag the Label item from the My Base Classes category, a Label with a base class of _Label from the _Base.vcx class library will be dropped. You can also drop a tool to the current active designer by double-clicking on the item in the Toolbox or pressing the Enter key. Additionally, if a designer workspace is open and a tool is selected, an Add to > shortcut menu selection will appear with a list of available workspaces to drop to as sub-items. In addition to using the mouse, you can activate an item's shortcut menu by pressing F10. This provides accessibility to the designers for keyboard users.

The Toolbox will also support items that represent builders or wizards, ActiveX controls, XML web services, and text scraps. In addition to these items, the Toolbox can represent file-based resources like databases, tables, images, reports, labels, menus, forms, applications, programs and projects. These items can also perform other actions by accessing their shortcut menus. Take a look at the My XML Web Services category. This category contains a tool called Register. When you click this tool to register an XML web service, it calls the Visual FoxPro XML Web Services Registration wizard. After you register your XML web service and click Done, the Toolbox category is refreshed and your XML web service item is displayed in the category.

The items in the categories can be dragged within the category to display in a user defined order. Items can also be dragged from one category to another. When this is done, the item is removed from the current category and added to the category in which it was dropped. One exception is the Favorites Category. When items are dragged here, a copy of the item is added to this category.

Item Types and Default Behaviors

The Toolbox inherently supports many types of items and their behaviors. They are:

Class Library-Based Class - These items represent classes that can be designed in the class designer (Checkbox, Label, TextBox, Form, etc.). These classes are defined in a class library file (.vcx). You can drag-drop this type of item to class and form designer workspaces to drop an object instance. You can also drag-drop to the text editor or command windows to create object instantiation calls. Modify and Create subclass are also available from the shortcut menu. Selecting Modify will open the class designer for that class. Selecting Create subclass will open the Visual FoxPro New Class dialog (CREATE CLASS). The form class items also have Create form available on the shortcut menu. Selecting this menu item will create a new form (.scx) that inherits from the form class.

Program-Based Class - These items represent classes that are defined in a program file (.prg). Drag-dropping works the same as the class library-based class items. Modify is also available from the shortcut menu. Selecting Modify will open the program file containing the class definition.

Base Class - These items represent Visual FoxPro base classes that are contained in the VFP Base Classes category. Drag-dropping works the same as the class library-based class items. Selecting Create subclass from the shortcut menu will open the Visual FoxPro New Class dialog (CREATE CLASS).

Class Library File- These items represent the class library files themselves (.vcx). Drag-dropping a class library item to an editor or command window will drop the file path and name as text. Clicking on the item will open the Modify Class dialog which is the same as selecting Modify on the shortcut menu.

Program - These items represent program files (.prg;.mpr). Drag-dropping a program item to an editor or command window will drop the file path and name as text. Clicking on the item will open the file in the editor which is the same as selecting Modify on the shortcut menu. You can also select Run directly from the shortcut menu to run the program.

Form - These items represent Visual FoxPro form files (.scx). Drag-dropping a form item to an editor or command window will drop the file path and name as text. Clicking on the item will open the form in the form designer which is the same as selecting Modify on the shortcut menu. You can also select Run directly from the shortcut menu to run the form.

Menu - These items represent Visual FoxPro menu files (.mnx) Drag-dropping a menu item to an editor or command window will drop the file path and name as text. Clicking on the item will open the menu in the menu designer which is the same as selecting Modify on the shortcut menu.

Report - These items represent Visual FoxPro report files (.frx). Drag-dropping a report item to an editor or command window will drop the file path and name as text. Clicking on the item will open the report in the report designer which is the same as selecting Modify on the shortcut menu. You can also select Run directly from the shortcut menu to run the report.

Project - These items represent Visual FoxPro project files (.pjx). Drag-dropping a project item to an editor or command window will drop the file path and name as text. Clicking on the item will open the project manager which is the same as selecting Modify on the shortcut menu. Database - These items represent Visual FoxPro database files (.dbc). Drag-dropping a database item to an editor or command window will drop the OPEN DATABASE command with the file path and name. You can also select Open directly from the shortcut menu to open the database. Clicking on the item will open the database in the database designer which is the same as selecting Modify on the shortcut menu.

Table - These items represent Visual FoxPro table files (.dbf). Drag-dropping a table item to an editor or command window will drop the USE command with the file path and name. You can also select Open directly from the shortcut menu to open the table. Drag-dropping a table item to the form designer, or double-clicking when a designer is open, will add a grid to the form and the table to the data environment. By default, it drops the VFP base class Grid. You can change this class on the VFP Options dialog Field Mappings tab accessed from the Tools menu. Select the Multiple type and click Modify to change the class and class library information. If no designers are open, double-clicking on the table item will browse the table which is the same as selecting Browse that appears on the shortcut menu. You can also select Modify from the shortcut menu to open the table designer.

Image - These items represent image files (.ani;.bmp;.cur;.dib;.gif;.ico;.jpg). Drag-dropping an image item to the designers, or double-clicking when a designer is open, will drop a image control with the picture property set. You can also select Open from the shortcut menu to open the image in your default image editor. This is controlled by the Windows OS (ShellExecute) and has the same effect as double-clicking on the image file in Windows Explorer.

Application - These items represent Visual FoxPro application files (.app). Drag-dropping an application item to an editor or command window will drop the file path and name as text. Clicking on the item will run the application which is the same as Run that appears on the shortcut menu.

Text File - These items represent text files (.txt). Drag-dropping a text file item to an editor or command window will drop the file path and name as text. Clicking on the item will open the file in the editor which is the same as selecting Modify on the shortcut menu.

Text Scrap - These items are pieces of text. Select and drag text to the Text Scrap category to create a text scrap item. Drag-drop a text scrap to an editor window, command window, or other Windows application that supports drag-drop text. Text scrap items can also be evaluated using the Visual FoxPro text merging feature so that code can be embedded in the text scrap and is evaluated when it is dropped. Drag-dropping a text scrap to the designers will drop label controls for each line in the scrap. Select Copy to clipboard from the shortcut menu to copy the contents of the text scrap to the Windows clipboard.

ActiveX Control - These items represent loaded ActiveX components. You can drag-drop this type of item to class and form designer workspaces to drop an OleControl. Or drag-drop to text editor or command windows to create object instantiation calls. You can also select Open in object browser from the shortcut menu to browse the component's properties, events and methods.

XML Web Service - These items represent registered XML web services. You can drag-drop this type of item to class and form designer workspaces to drop a web service proxy class you specify. By default the WSHandler class in the _ws3client FoxPro foundation class library is used. Drag-drop XML web service items to text editor windows to automatically generate proxy code.

Other Windows File Types - Items based on any Windows file type that does not have specific behaviors supported by the Toolbox can still be kept in the categories as a generic File type. In this case clicking on these items or selecting Open from the shortcut menu will launch the default Windows editor. This is controlled by the Windows OS (ShellExecute) and has the same effect as double-clicking on the file in Windows Explorer.

Special Drag-Drop Behaviors

There are some special drag-drop behaviors you should note when working with container and member classes. Drag-dropping a class item onto a container on the designer workspace will add the control directly into the container. For instance, if you drop a textbox onto the first page of a pageframe, the textbox will be added to page1. If you do not want this to happen, hold the Control key while drag-dropping (CTRL+Drag-drop) to drop the control on top of the container. This behavior makes designing a custom grid much easier. You can add controls directly into columns of a grid by dropping the item directly over the column. By default, a Visual FoxPro base textbox named Text1 is contained in a grid column when you set the ColumnCount property of a grid. When designing a custom grid, you typically want to use your sub-classed controls in the columns. When you drag your class item to the grid column, a message box will prompt you as to whether you want to replace the Text1 control with your control. If you say yes, your control replaces Text1 in the column. If you say no, your control is added to the column. Additionally, if you drag a control like a textbox to the grid itself, you will be asked if you want to add a column to contain this control. This way you do not have to add columns before adding their controls, you can do it all in one step as shown in Figure 3.

Figure 3. A column can be automatically added when dropping a control directly to a grid.

The Toolbox supports member class items as well. Member classes are classes that belong to a parent container. Page, Column, Header are examples of these classes. When drag-dropping a member class item onto a designer workspace like a form, the parent object will be dropped and its MemberClass and MemberClassLibrary properties will be automatically set for you. For example, if you have a sub-class of the Page class called MyPage that you have added to the Toolbox and drop that onto a new form, the Visual FoxPro base PageFrame will be dropped and its MemberClass will be set to MyPage. You can specify the number of members to create in this situation by setting the MemberCount property of the tool item. To access properties of a tool item, select Properties from the shortcut menu of the item in the Toolbox. You can also specify the parent class to drop by setting the ContainerClass and ContainerClassLib properties of the tool item in the same manner. This way when the MyPage tool is dropped to a form, instead of creating a Visual FoxPro base PageFrame, it will create a pageframe of the class you specify in those properties.

When you drop member class items to container classes in which they belong, the MemberClass and MemberClassLibrary properties will be automatically set if they are empty. For instance, if you drop the MyPage class item onto an existing pageframe, the MemberClass and MemberClassLibrary properties of the pageframe will be set. However, if those properties are not empty a message box will prompt you if you want to delete the current member class objects and add your new member class. Remember, there can only be one member class defined at design-time for container classes. For more information on member classes, see the Visual FoxPro Help.

Using the Customize Toolbox Dialog

The Customize Toolbox dialog is accessed via the Toolbox shortcut menu Customize Toolbox. Here is where the you can mange all the items and categories of the Toolbox all in one interface. The dialog contains a tree-view of category names on the left hand side so that you can manage multiple categories at one time. The category where the shortcut menu action was initiated is automatically selected. The right hand pane changes content depending on what is selected in the tree view. If a category is selected, a category toolbar is displayed at the top of the form. Below the category toolbar are the view and item toolbars. Below that is the tool item grid.

The contents of the item grid changes depending on the view selected from the dropdown list. At the bottom right-hand side of the form there are two buttons: OK and Cancel. Clicking OK saves all changes, closes the form, and updates the Toolbox. If you click Cancel, a confirm dialog is displayed if changes were made to any of the information on the form. If you answer yes, all changes are discarded and the form closes.

Figure 4. The Customize Toolbox dialog with a category selected.

Working with Categories

There are five types of Toolbox categories that can be created; General categories, Dynamic folder categories, Text Scrap, Registered ActiveX controls, and Registered XML Web Services. When you create a new category, you must select a category type. All category types can support any item type. This means you can place items in any of the category types that represent any of the supported tool types. However, some category types have additional behaviors available from their shortcut menus or when they are opened. The following is a list of category types you can choose from:

General category - This category does not have any extra special behavior. It is a static category that can contain any type of tool item.

Dynamic folder category - You specify a file system folder and file types for this type of category to read. When the category is opened, the contents are dynamically filled based on the contents of the file system folder.

Text scraps - This type of category creates scrap tools when text is selected and dropped to this category. You can also select text form other Windows applications like Word and drag it to the Text scrap category to automatically create a text scrap. Drag the text scrap from the Toolbox into editor windows or other Windows applications to drop the text. Text scraps can also be created using Visual FoxPro text merge features so that code can be embedded in the scrap and evaluated when it is dropped.

Registered ActiveX controls - This type displays all the Visual FoxPro loaded ActiveX controls. You specify these controls from the Visual FoxPro Tools menu under Options and selecting the Controls tab.

XML web services - This type of category displays all the Visual FoxPro registered XML web services specified in the Visual FoxPro intellisense manager.

To remove a category, select the category from the tree-view and click the Remove Category button on the category toolbar. This can also be done from the Toolbox directly by activating the category's shortcut menu and selecting Delete. A confirm delete dialog appears prompting if it is okay to delete the category. If yes is selected, all the items in the category are removed from the Toolbox as well. You can only remove user-defined categories.

To add a category, click the Add Category button on the category toolbar. This option is also available from a category's shortcut menu on the Toolbox. An Add Category dialog appears where you can type in the name of the new category and select a category type. Click OK to add the category to the bottom of the Toolbox. Dynamic folder categories require you to select the folder and file types to read before the category can be created. When you select a dynamic folder category type and click OK on the Add Category dialog, the category properties are displayed where you specify the folder and file types. Once these are selected click OK and the dynamic folder category is added to the bottom of the Toolbox.

To reorder a category in the tree-view, select the category and click the folder up/down arrows on the category toolbar. The category will move up or down in the tree-view indicating the new position.

Refresh Category is located on the category toolbar as well as the Toolbox shortcut menu. Refreshing a category re-reads the class library files (.vcx;.prg) contained in the selected category and creates Toolbox items for any new classes found in them and removes any items which represent classes that were deleted. Any items that were already in the customize grid and marked selected remain selected, and any items already in the grid that are marked unselected remain unselected when the refresh takes place. A category only needs to be refreshed if the category contains items that represent classes that have been removed from a class library or if new classes that have been added to the class library need to be exposed as Toolbox items. If the category is a dynamic folder category, selecting Refresh Category re-reads the folder from disk and updates the items that have been added, deleted or renamed via the windows file system. Dynamic folder categories are also refreshed when the Toolbox is restarted or refreshed. Refresh Toolbox is also located on the category toolbar of the Customize Toolbox dialog. Selecting this displays a message box “Would you like to refresh all items in the Toolbox?”. If you select yes, a refresh of the entire Toolbox (all categories) takes place.

Category Properties

The category properties dialog can be accessed from either the shortcut menu and selecting Properties or by selecting the category from the tree view on the Customize Toolbox dialog and clicking the Category Properties button from the category toolbar. Category properties can vary depending on the type of category.

Figure 5. General category properties dialog.

All types of categories share these common properties; category type, category name, help text, help file and help context id. Category type displays the category type that was selected when the category was created.

Once a category is created, you cannot change its type so this property is read only. Category name displays the name that appears on the category button on the Toolbox. You can rename a category here. You can also rename a category directly from the Toolbox by right-clicking on the category button and selecting Rename from the shortcut menu. Enter information in the help text property to display tool tip text for the category. This text also displays in the help text section at the bottom of the Toolbox.

If URLs are typed into the help text property, they are displayed in this section as hyperlinks. If you have a help file and help topic you want to display when the category is selected and F1 is pressed, select the help file and enter the help context ID. If you do not specify a help file, the Visual FoxPro Help system will be used.

Categories can be marked globally inactive from this properties dialog. The checkbox at the bottom of the dialog, when checked, indicates that the category should not show up in the Toolbox. This also excludes it from any filters if they are applied.

The default set of categories that ship with the Toolbox cannot be permanently deleted, but can be hidden from view by checking this checkbox. When a category is marked inactive, it shows up gray in the Customize Toolbox dialog tree view and on the filter categories listing.

In addition to the properties we just discussed, dynamic folder categories also have folder and file type properties where you specify a file system folder and file type (or types) for this category to display. When this category is opened in the Toolbox, the contents of the category are dynamically filled based on the contents of the folder.

An Open option is also available from the shortcut menu. Selecting this will open Windows Explorer to the specified folder.

Figure 6. Dynamic folder categories display files of a certain type contained in a file system folder.

Registered XML web services categories display all the Visual FoxPro registered XML web services specified in the Visual FoxPro intellisense manager.

In addition to the properties displayed for general categories, registered XML web services categories also have a code template where you can override the default drop text for the web services.

By default, when you drop an XML web service item into the program editor, proxy code is generated for you. This code instantiates the WSHandler class in the _ws3client FoxPro foundation class library. This web service handler is the core client class used to communicate with an XML web service. For more information on XML web services and the FoxPro foundation classes, see the Visual FoxPro Help.

When you drag an XML web service item to a designer, the WSHandler class is dropped with the appropriate web service properties filled out automatically for you. If you do not want to use the default web service handler, there is a place on the category properties to specify the class library and class name to use.

There is also a place to specify property settings you may want to set automatically when it is dropped.

Figure 7. By default the WSHandler FoxPro foundation class is used when you drag an XML web service item from the Toolbox to a designer.

Figure 8. On the XML web service category properties you can specify the template, class library and class name to use when an XML web service item is dropped to editors and designers.

Working with Items

The Customize Toolbox dialog helps you manage tool items which are displayed in the item grid. The view toolbar contains a dropdown list of options used to display the selected item types. The three options are: <all>, Visual FoxPro class libraries, ActiveX controls. Selecting different item views changes what is displayed in the grid and what action buttons are displayed in the item toolbar above the grid. The <all> view displays all the items in the selected category and the item types. When the Visual FoxPro class libraries view is selected, the grid displays any class-based items for the selected category. In this view the grid also displays the class name, parent class, class library, and the last modified date of the class library file. The ActiveX controls view displays all controls that are registered on your computer as unchecked items. Selected items in the category appear at the top of the list. In this view the grid also displays the component name and the path and filename of the component file.

The first column of the item grid contains a checkbox which indicates items that are displayed in the category. This column and the Item Name column are locked when the grid is scrolled horizontally. You can edit the names of the tool items directly in the Item Name column. Show checked items only is a checkbox next to the view dropdown. When checked, this shows only items that are selected in the item grid. If it is not checked, all items are shown. If the items inside the category are dynamically created (Dynamic folder, XML web service, ActiveX control categories) then the grid displays a read only message: Dynamic Category - click on Category Properties to modify. This message is displayed when the <all> view is active.

Depending on the view, there are different item toolbar buttons available. The Item Properties button is always active. The Sort Alphabetically and the reorder buttons are enabled if the <all> view is active. When the this view is selected the Add Item... and Remove Item buttons are available from the item toolbar which allows you to add any type of item to the Toolbox. Selecting the Add Item… button displays the Add Item dialog. This dialog is necessary when adding items in the <all> view so that the Toolbox knows what type of behavior and properties to assign to the item.

Figure 9. The Add Item dialog is displayed when you select "Add Item..." from the item toolbar on the Customize Toolbox dialog.

When you select File, an Open file dialog is presented allowing you to select any file. The Toolbox will infer the type of all the file-based items based on the file extension. The item is then added to the grid at the bottom of the list and is marked as selected. When you select Class, the Open file dialog appears where a class library (.vcx) or program (.prg) file can be selected. The class library is read and all classes contained within it are added as items to the grid and selected by default. Class items that you want hidden from the Toolbox category can then be cleared in the grid. If Text scrap or Script is chosen, the Item Properties dialog will appear so you can enter the text. If ActiveX control is selected, the item grid will change to the ActiveX view so you can select the controls to add to the Toolbox. Because ActiveX controls are installed on the system outside of Visual FoxPro, adding an AcitveX control means to simply add an ActiveX based item to the Toolbox. In the ActiveX Controls view, the item grid will display the registered ActiveX controls on the system. From there, check the controls that should be included in the category. If there are already controls included in the category, they will appear at the top of the list.

To quickly add any item to any general category on the Toolbox, drag files from Windows explorer directly over the category button. If the file is a class library (.vcx, .prg), all the classes inside the library will appear in the category.

Figure 10. Selecting "Remove Item" on an item that is part of a class library will remove all the items that represent classes in that library.

To remove a file or ActiveX control item from the Toolbox, select the item in the item grid and click the Remove Item button from the item toolbar when the <all> view is active. This can also be accomplished from the shortcut menu on the item in the grid and selecting Remove, or from the item shortcut menu on the Toolbox itself and selecting Delete. A confirm dialog asks “Are you sure you want to remove this item from the Toolbox?”. Click Yes to remove the item from the Toolbox. To simply hide the item, clear the checkbox in the first column of the item grid. This leaves the reference, but the item will not be visible in the category. The item can be quickly reactivated by checking the checkbox again.

To remove an entire library of tools from the Toolbox, select one of the tools contained in that library from the grid and select the Remove Item button from the item toolbar. This can also be accomplished from the shortcut menu on the item grid and selecting Remove. A confirm dialog asks “Would you like to remove this class library's classes from the Toolbox?”. Click Yes to remove all the class items based on that library from the Toolbox. Click No to simply uncheck the item, and click Cancel to leave the item unchanged.

When you want to work solely with class items, select the Visual FoxPro class libraries view. When this view is active you can easily add and remove class libraries by selecting the appropriate item toolbar buttons, Add Class Library and Remove Class Library. You can also add class libraries directly from the Toolbox shortcut menu by right-clicking on the Toolbox and selecting Add class library. The Add Class Library dialog is displayed so you can select an existing category from the list or type in a new category name in the combo box. Then select the class library file by clicking on the ellipsis button. A class library (.vcx) or program (.prg) based library can be selected. All the classes in the library are then added as items to the Toolbox.

Figure 11. You can add items from class libraries to new and existing categories directly from the Toolbox shortcut menu.

To reorder an item in the grid, select the item and click the up/down arrows on the right side of the item toolbar. The item will move up or down in the grid indicating the new position. Items can also be dragged to new positions on the Toolbox itself. Clicking the Sort Alphabetically button will sort the items in the current category by item name. It is available from the Customize Toolbox dialog item toolbar and also from the item grid shortcut menu when the <all> view is active.

You can activate an item shortcut menu by right-clicking on the item in the item grid. If the <all> view is active, the menu displays Item Properties, Remove, Select All, Clear All, and Sort Alphabetically. To quickly select all items in the grid, choose Select All.

This checks all the checkboxes in the first column of the item grid. To quickly clear all items in the grid, choose Clear All. This clears all the checkboxes in the item grid.

Item Properties

The item properties dialog can be accessed from either the shortcut menu and selecting Properties or by selecting the item from the item grid on the Customize Toolbox dialog and clicking the Item Properties button from the item toolbar. Item properties can vary depending on the type of item.

Figure 12. The Class Item Properties dialog.

All types of items share these common properties; item type, item name, help text, help file and help context id. Once an item is created, you cannot change its type so this property is read only. Item name displays the name that appears on the item button on the Toolbox. You can rename an item here. You can also rename an item directly from the Toolbox by right-clicking on the item and selecting Rename from the shortcut menu. Enter information in the help text property to display tool tip text for the item. This text also displays in the help text section at the bottom of the Toolbox. If URLs are typed into the help text property, they are displayed in this section as hyperlinks. If you have a help file and help topic you want to display when the item is selected and F1 is pressed, select the help file and enter the help context ID. If you do not specify a help file, the Visual FoxPro Help system will be used. Items can be marked globally inactive from this properties dialog. The checkbox at the bottom of the dialog, when checked, indicates that the item should not show up in the Toolbox. This is the same as clearing the item in the item grid on the Customize Toolbox dialog.

In addition to these properties, file-based items also have a file name property where you specify a path and file name. This property is available for class library file (.vcx), program (.prg;.mpr), form (.scx), menu (.mnx), report (.frx), project (.pjx), database (.dbc), table (.dbf), image (.ani;.bmp;.cur;.dib;.gif;.ico;.jpg), application (.app), text file (.txt), and any other Windows file types. Table items and image items also have builder, object name and an object properties editor so that you can customize the image and grid objects that are dropped to designer workspaces. The object name property is the name that is used for the object when the item is dropped to the designers. Application items have a checkbox at the bottom of the Item Properties dialog that indicates whether or not to refresh the category after the application runs.

This gives you or third-party vendors the ability to write applications that modify the contents of the Toolbox category. An example of this is the Register tool that ships with the My XML Web Services category.

The item properties for text scrap items include a text scrap edit box where you can edit the contents of the text scrap. Text scraps can also be evaluated using text merge when they are dropped so you can embed code in the scrap between the text merge characters; << and >>. This is indicated by the Evaluate using text merge checkbox under the text scrap edit box. For example, if you enter text as follows:

The date is <<DATE()>>

Then when you dropped this text scrap item to an editor window, DATE() would be evaluated and you would end up with something like:

The date is 01/01/2003

ActiveX items display class library and class name as read-only properties on their Item Properties dialogs. Class library indicates the file that contains the component. Class name displays the name of the component as it appears in the registry. ActiveX items also have object name and an object properties editor so that you can customize the OleControl objects that are dropped to designer workspaces.

Class items display the class library and base class on their Item Properties dialogs. Class library indicates the class name and also the class library file (.vcx;.prg) displayed in parenthesis. This can be changed by clicking the ellipsis button and selecting a new class library and class from the Open class dialog. Base class is a read-only property that indicates the Visual FoxPro base class. Class items also have builder, object name and an object properties editor so that you can customize the objects that are dropped to designer workspaces.

Figure 13. You can set properties on object instances when they are dropped to designers from the Item Properties dialog.

You can select how builders are activated for items you can drop to designers by setting the builder property. The settings can be: Use Builder Lock setting, Always invoke Builder, and Never invoke Builder. Select Use Builder Lock setting when you want to globally control how builders are activated from the Toolbox Options dialog. There you can set whether to invoke builders when items that have the Use Builder Lock setting selected are dropped to the designers. You can override this for individual items by selecting Always invoke Builder, or Never invoke Builder.

Use the object properties editor to set properties on the object instances when they are dropped to designers. Only properties that are not read-only can be set. The type of data you enter must also be the same type as the property otherwise it is ignored. You can create dynamic properties by entering VFP functions between parenthesis for the value. The functions are evaluated when the item is dropped so be careful using variables that have not been declared in the design environment. If the evaluation of the property fails, it is treated as a string literal. In that case, if the property is not a character type, it is ignored. To add a new property, click the Add button next to the Properties list box. This will open the Set Object Property dialog which allows you to select a property from the list and enter a value. To edit a value, select the property in the Properties list and click Edit. To remove the property, select it and click Remove.

For member classes you can specify the number of members to create by setting the MemberCount property. For instance, if you specify the MemberCount of a page item be set to 2, when the item is dropped to a designer, two pages will be created in the pageframe. (Remember, if you drag a member class to a designer, the Toolbox automatically creates the parent container for you.) You can also specify the parent class to drop for member classes by setting the ContainerClass and ContainerClassLib properties of the item. This way when the member class item is dropped, instead of creating a Visual FoxPro base container, it will create a container of the class you specify in those properties.

Setting Up Filters

Filters allow you to set up numerous categories but only display a finite amount in the Toolbox at one time. For instance, you can set up filters to hide and show groups of categories depending on the project you are working on. The filter dialog is displayed when you select Filters from the tree view on the Customize Toolbox dialog. When this is selected, the form displays a filter toolbar, the current active filter, and the filter name. Below this are two list boxes, one containing your defined filters and one containing the categories. Checkboxes are selected in the category list based on whether they are part of the selected filter.

Figure 14. The Filters section of the Customize Toolbox dialog allows you to set up groups of categories to display in the Toolbox.

To add a new filter click the New Filter button on the toolbar. The name "Filter 1” is automatically assigned for you and is selected in the textbox. It is also automatically added to the Defined filters list. You can change the name by typing a new name in the Filter name textbox. Select the categories you want to appear when the filter is applied by checking the appropriate checkboxes next to the category names. If a category is marked inactive on its Category Properties, the category will be hidden from view no matter what filter is in effect. Categories that are marked inactive show up gray in the categories list. You can delete a filter by selecting it in the Defined filters list and clicking the Delete Filter button.

To apply a filter on the Toolbox select the filter from the list and click the Apply Filter button. The current filter display at the top of the form changes to the filter name you selected. To quickly apply a filter from the Toolbox itself, select Filter from the Toolbox shortcut menu. The Filter menu will display the filter names as sub-items that you can choose from. To clear the filter and display all categories in the Toolbox, click the Clear Filter button on the toolbar. This button is enabled only if there is a current filter already applied. The current filter display at the top of the form changes to (none – all categories are visible). You can also quickly clear filters from the Toolbox shortcut menu by selecting Filters then none.

Figure 15. You can quickly apply and clear filters from the Toolbox shortcut menu.

Class Items Information

The Class Items Information is where you can specify naming conventions as well as drop text templates for class items in the Toolbox. To access this information select Class Items from the tree view on the Customize Toolbox dialog. There are three options available for selecting the default naming convention when class items are imported into the Toolbox.

Naming Convention Example
ClassName (Library) _checkbox (_BASE)
ClassName _checkbox
Library.ClassName _BASE._checkbox

The first option is selected by default. You can also optionally include a code template to use when drag-dropping and CTRL + drag-dropping tools to the editor windows. This overrides the tool’s default text. There are text merge values that are also available to you.

Value Description
<<classname>> Returns the class name
<<objectname>> Returns the object name set in the item properties
<<classlib>> Returns the class library name
<<baseclass>> Returns the base class name

The Edit buttons bring up a larger program editor window which works with intellisense and color coding. If you do not enter anything in the drop text templates, the default template for drag-dropping is an object instantiation call:

<<objectname>> = NEWOBJECT("<<classname>>","<<classlib>>") 

And the default template for CTRL + drag-dropping is a DEFINE CLASS construct:

DEFINE CLASS My_<<classname>> AS <<classname>> OF <<classlib>>
  PROCEDURE Init
  ENDPROC

  PROCEDURE Destroy
  ENDPROC

  PROCEDURE Error(nError, cMethod, nLine)
  ENDPROC
ENDDEFINE

Toolbox Options

To access the Toolbox Options click on Options in the tree view on the Customize Toolbox dialog. This will display the Toolbox option information. There is a set of checkboxes at the top of the form which allows you to make the following selections:

Option Description
Run associated builders Specifies that builders are displayed automatically in the Form Designer when you create a control that has a builder registered to it and the builder item property is set to Use Builder Lock setting.
Display Toolbox help text section If this is checked the Toolbox will display the tool tip text for the selected item in the visible help description section. If it is not checked, the section is not visible.
Show Tooltips If this item is checked then Toolbox item tooltips are displayed.
Always on top When checked, the Toolbox will always appear in front of other windows.
Double-click to open an item If this is checked then file-based items that appear on the Toolbox must be double-clicked to open. Otherwise a single click opens the item.
Set CurrentControl property when a control is dropped onto a grid column If this is checked then when a control is dropped onto a grid column, the CurrentControl property of the column is automatically set to the dropped control.
Prompt to remove text1 control when dropping new control onto a grid column If this is checked then when a control is dropped onto a grid column, you are prompted to remove the default Text1 control. Otherwise the Text1 control is not automatically removed.
Allow toolbox to be minimized The Toolbox will display the minimize box in the title bar if this is selected.

You can set how fast or slow categories scroll when you mouse over the scroll arrows by adjusting the value contained in the Category scroll speed spinner. Five milliseconds is the fastest and 100 milliseconds is the slowest. The location and table name of the Toolbox content is also displayed here. You can switch between Toolbox content tables while the Toolbox is still running by specifying a different table name here.

The default font for items displayed on the Toolbox is Tahoma, 8 point, Normal. If a different font is desired, the Toolbox category and tool button fonts can be changed by selecting the Font… button. This brings up the Font selector dialog where you can select a new font. Only the Toolbox form itself is affected. Property sheets and dialogs are not affected.

Clicking the Clean Up Toolbox button performs a PACK on the Toolbox content table which permanently removes all deleted records and reduces table size. You can restore the Toolbox content by selecting Reset Toolbox to Default. You will be prompted: “Do you want to maintain new categories and Toolbox items that were added by you or a third-party vendor?” If you respond Yes, only the default categories that were shipped with VFP are restored to their original content. If you say No, the entire Toolbox table is restored to the default installation, removing all user customizations. In either case, before the Toolbox table is modified, a backup copy is made in the same directory.

Conclusion

The Visual FoxPro Toolbox is yet another amazing IDE feature that speeds up our development time. It not only allows us to manage classes and components but also projects and resources. It replaces the Form and Class toolbars and gives us more control over the design envoronment. Though it is beyond the scope of this article, the Toolbox is extensible so you can add your own tool types and behaviors. It also provides a way for third-party vendors or enterprise architects to create specialized tool sets for developers. Look for that information to be published on MSDN. I hope this article will help you take advantage of all the great featues of the Visual FoxPro Toolbox.

Beth Massi, Microsoft Corporation
Beth Massi is a Program Manager at Microsoft on the Visual Studio Community Team working with the Visual Basic Team producing developer content on MSDN (http://msdn.com/vbasic/) and her blog (http://blogs.msdn.com/bethmassi). As a VB community champion and a long-time member of the Microsoft community she also helps run the East Bay.NET user group and is a frequent speaker at various software development events. Before Microsoft, she was a Senior Architect at a health care software product company and a Microsoft Solutions Architect MVP. Over the last decade she has worked on distributed applications and frameworks, web and Windows-based applications using Microsoft development tools in a variety of businesses. She loves teaching, sports, modifying cars and drinking beer.
More articles from this author
Beth Massi, July 1, 2002
COMCodebook is a middle-tier framework written in Visual FoxPro originally developed by Flash Creative Management, Inc. the creators of the Codebook framework. It has been tested with Visual FoxPro 6 Service Pack 5 and higher. It is compatible with a variety of backend databases such as SQL-Server...