Session E-OLE

Introduction to OLE Automation with Visual FoxPro 3.0

Jim Booth


What is OLE?

OLE is a technology in the Windows world that allows the inclusion of an object or document from one application in another application. The application that "owns" the object or document is called the Server while the containing application is called the Client.


For example, a Microsoft Word document may contain a Microsoft Excel spreadsheet, in this scenario Microsoft Word is the client and Microsoft Excel is the server. In OLE version 2.0, when the user tries to edit the spreadsheet, Excel will take over the menu and the toolbar but the user will still feel that they are in Word. This is called In-Place editing.


Visual FoxPro complies with OLE 2.0 standards. Another feature of OLE 2.0 is OLE Automation. OLE Automation allows us to program the OLE object as if it were just another object in our application. Each OLE server will expose different methods and properties to the client, we can use these methods and properties to control the OLE server and thereby modify the OLE object.


The newest direction in application development is componentization. In this approach to development we make use of various components to produce a finished application. The components may be very simple or they may be as complex as Excel or Word.

For example, we may provide word-processing features in our Visual FoxPro application by using Microsoft Word with OLE Automation. Or we could provide graphing features through Microsoft Excel. OLE Automation is the functionality that allows this approach to development to be a reality.

Imagine a situation where you need to provide the ability to produce a corporate annual report from your Visual FoxPro application. The annual report needs to contain text, graphs, spreadsheets, and other data from your Visual FoxPro tables. You can easily write the program that will compile the required data, but how do you produce the graphs, spreadsheets, and format the printed document? With OLE automation you can send your data to Microsoft Excel to get the spreadsheets and then tell Excel to draw the required graphs. Then use Microsoft Word to produce the document including the graphs and spreadsheets you created using Excel. Finally, you can tell Word to print the document. Your user gets a finished annual report and thinks your Visual FoxPro application did it all by itself.


In the past you would use DDE (Dynamic Data Exchange) to communicate between applications. So what is the difference between DDE and OLE?

DDE is a technology that would allow one application, the client, to communicate with another application the server. The communication was centered around the applications and not the documents, or objects. DDE requires specific and specialized information about the server application in order to accomplish the various tasks you might want.

OLE, on the other hand, is communication with the document, or object, and not the application per se. The properties and methods that are exposed are somewhat consistent across various different OLE servers, and they are at least syntactically similar. The communications that go on in OLE are the same, syntactically, as any other object manipulation you do in Visual FoxPro, following the container to object hierarchy as in;


to call the refresh method of an OLE object stored in a control named OleControl1 within the current form.

It is often said that DDE is the technology of yesterday and that OLE is the technology of tomorrow. If that statement is really true then we should have need, today, for both of these technologies because of the existence of software applications that predate the current version of OLE.


The OLE controls available in Visual FoxPro are container controls that can contain an OLE object. There are two OLE controls, the OLE Bound Control and the unbound OLE control. Both of these are containers with the major difference between them being that the bound control is bound to a general field in a DBF table while the unbound control is not. These two controls are referred to as OLEControl and OLEBoundControl respectively.

One additional difference is that the OLEControl can contain an OLE Custom Control (OCX) as well as an insertable OLE object while the OLEBoundControl cannot contain an OCX. More on OLE Custom Controls in the next section.



Visual FoxPro Professional Edition ships with a number of OLE Custom Controls. The Help file for the Professional Edition documents these controls. The controls that ship with Visual FoxPro Professional Edition are;

Purpose File Name Description
Communications MSCOMM32.OCX Allows you to control communications through the serial ports on your computer.
Messaging Application Program Interface (MAPI) MSMAPI32.OCX Provides access to the Microsoft Mail services to your Visual FoxPro application.
Outline MSOUTL32.OCX Provides the facilities of an expanding and contracting list control to display item hierarchies.
Picture Clip PICCLP32.OCX Provides for the storage and retrieval of multiple Bitmap images in a single file.


These controls are documented in the Professional edition help file under the OLE Controls Overview heading. The code disk contains an example form using the Outline control.


OLE Automation refers to the process of controlling an OLE object or control through program code. The examples disk contains three example forms Outline.scx, ExcelOLE.scx, and WordOLE1.scx which demonstrate the use of OLE Automation techniques for controlling the Outline control, and Excel sheet, and a Word document respectively.

These forms will be explained in detail during the session.