Home » Uncategorized » FoxPro Tips: Object Browser
Mar
14

FoxPro Tips: Object Browser

The Object Browser was new in Visual FoxPro 7. It exposes the public and protected interfaces of COM object libraries and ActiveX controls. Inside these libraries is a wealth of information concerning the properties, events, methods, constant values, and classes available for developers. This tool is very important to developers who write Automation code and need to understand the documented ways of using a particular Automation object.

Determining the values of constants defined in a COM object

One of the truly grueling tasks developing automation code is determining the constants used in the examples. These constants can be translated into #DEFINE code. Before you had the Visual FoxPro Object Browser you needed to trudge through Help files, hope examples documented the values, or use a tool like the object browser found in the VBA editors of Microsoft Office to find these values. This is a time consuming process for sure. Tools like the West Wind GetConstants.EXE read the type libraries and generate the #DEFINE code, which is easily compiled by Visual FoxPro.

The Object Browser can generate the #DEFINE code efficiently and is a real time saver. To accomplish this, open up the COM or ActiveX component, drill down the TreeView to expose the Constants node. Open up a program editor (program, or class method). Drag the Constant branch and drop it in the editor. Not only is the #DEFINE code typed in with the constant name and value, but the documentation for the constant is also included as a comment for the #DEFINE if the constant has a description. If you drag the constants branch you will get all the constants in the editor. You can also drag individual constants if you only need specific ones.

GOTCHA: I have experienced constants that are decimal values getting rounded to zero (with MapPoint). If this is the case, I recommend the GetConstants.exe from West Wind, which does not suffer from the same bug.

Use the Object Browser to create class templates to implement interfaces

A very powerful feature in Visual FoxPro is the capability to write code in our custom applications responding to events in other applications. For instance, you can write code to respond to a user closing a spreadsheet, or sending an email in Outlook, or doing a mail merge in Word. This is done with the IMPLEMENTS clause of DEFINE CLASS as well as the EventHandler() function.

The Object Browser assists you in writing tedious code in this respect. First open up the COM or ActiveX control in the Object Browser. Then drill down through the TreeView and locate the Interfaces node. Open up a program editor (program, or class method). Drag the interface node and drop it in the editor. The class definition is written, including the IMPLEMENTS and template code for each of the methods exposed. All you have to do at this point is rename the class from MyClass to something more descriptive, and add code to the appropriate method.

Find out the name of the OCX file to ship with my deployment setup

The Object Browser helps Visual FoxPro developers with numerous features for ActiveX controls. One of the simpler, yet more helpful items is displaying the actual file name for the OCX and other details about the control.

Open up the Object Browser and select an ActiveX control from the list. If you select the root node for the control there are details about the OCX displayed in the bottom pane of the Object Browser. Information like the file name, the Help file, and the GUID is presented for the developer. This can be handy when you need to find out what OCX file is to be included in a deployment package, and determine where the Help file is installed on the hard drive.

One Response to “FoxPro Tips: Object Browser”

  1. March 22nd, 2006 at 10:53 | #1

    Nicely written Rick! With respect to my particular case, I was actually thinking of building a class to handle exactly what you suggested.

    It would be very nice to wrap all of the automation work in a series of VFP classes to simplify the process long term.

    Thanks for stopping by my place!

Add reply