This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.
Multi-tier system designs often require that we use base classes that can't be defined visually. This means using PRGs to define our classes. The Class Browser built into VFP is a wonderful tool for navigating the hierarchy of class definitions. However, when we use programmatically defined classes, the value of the Class Browser is lost. This month, Jim Booth introduces Michael G. Emmons of Flash Creative Management (now GoAmerica), who has a solution for us.
Most of the classes we create in Visual FoxPro can be built using the visual class designer. For these visual classes, we have the Class Browser tool. However, there are a number of classes in Visual FoxPro that can't be created in the visual designer. Classes like the column, page, session, and others must be created in program code using the DEFINE CLASS construct. For these classes the Class Browser fails, but the Class Navigator from Michael Emmons succeeds.
One thing that I dislike is a developer tool that takes a genius to install it and get it working. Michael has given us a utility that installs as simply as is possible. Just copy the APP file, ClassNavigator.app, to any directory on your machine, and it's installed and ready to go.
The test run
To test this tool, I created two program files, as demonstrated in the following code:
* Testclass.prg DEFINE CLASS MyTest as Label MyProp = "Hello" PROCEDURE MyMethod ? This.MyProp ENDPROC ENDDEFINE * TestClass2.prg DEFINE CLASS MyOtherClass AS MyTest ; FROM d:\scratch\TestClass.prg MyOtherProp = "Goodbye" PROCEDURE MyOtherMethod ?This.MyOtherProp ENDPROC ENDDEFINE
Notice that the class defined in TestClass2 is a subclass of the one defined in TestClass.
Next, I ran ClassNavigator.app and was greeted by the screen shown in Figure 1.
There are four tabs—labeled Classes, Files, Options, and About—that are used in viewing the classes. The first tab we'll visit is the Files tab, and we'll select the Add button. In the file selection dialog box, I chose TestClass.prg; the resulting display is shown in Figure 2.
Switching to the Classes tab and expanding the tree gives the display shown in Figure 3.
The display has been expanded to show the existing details. You can see the filename and base class under Info, the Customer property under Properties, and the Custom method under Methods, just like the Class Browser would show us for a visual class definition.
Double-clicking on the class name in this display will open the editor with the program loaded for editing.
Hierarchies from multiple programs
Now return to the Files tab and open the TestClass2.prg file. The new Classes display is shown in Figure 4.
The Classes tab now shows us the hierarchy of these two classes, including the file information regarding each class.
Where to get ClassNavigator
This tool is included in the accompanying Download file. It's also available at www.comcodebook.com, where future updates will be posted first (as well as the COM Codebook application framework). The source code for the Class Navigator is included in the download. The tool is freeware; you're free to use or modify it to your desire, but you're restricted from selling it to anyone else.
Michael G. Emmons has given us a utility that allows us to view classes that are defined in programs rather than visual class libraries. With his tool, we can see the inheritance hierarchy of these classes even when they cross multiple program files. A simple double-click opens any one of the classes for editing.
Michael and Flash Creative Management (now GoAmerica) have graciously made this tool, as well as many other tools including a complete application framework, available to us all at no charge.