Share via


OLE Container Control

Creates an OLE container control.

OLEControl

Remarks

An OLE container control lets you add OLE objects to your applications. OLE objects include ActiveX Controls (.ocx files) and insertable OLE objects created in other applications such as Microsoft Word and Microsoft Excel. Unlike ActiveX Controls (.ocx files), insertable OLE objects do not have their own set of events. OLE container controls, unlike OLE bound controls, are not bound to a General field in a Visual FoxPro table.

Note that the type of ActiveX control placed in an OLE container control determines the properties, events, and methods available for the ActiveX control

For additional information about OLE objects in Visual FoxPro, see Sharing Information and Adding OLE.

Example

The following example adds an OLE Container control to a form, and uses the OleClass and DocumentFile properties to specify Microsoft Excel as the Automation server and a Microsoft Excel worksheet as the file to edit.

The DocumentFile property specifies a worksheet named Book1.xls in the EXCEL directory on drive C. This example will not work properly if the file and directory specified in the DocumentFile property do not exist; it may be necessary to modify the DocumentFile property to specify an existing directory and worksheet file.

* The DoVerb method is used to activate the worksheet for editing.

frmMyForm = CREATEOBJECT('Form')  && Create a Form
frmMyForm.Closable = .F.  && Disable the window pop-up menu

frmMyForm.AddObject('cmdCommand1','cmdMyCmdBtn')  && Add Command button
frmMyForm.AddObject("oleObject","oleExcelObject")  && Add OLE object

frmMyForm.cmdCommand1.Visible=.T.  && Display the "Quit" Command button

frmMyForm.oleObject.Visible=.T.  && Display the OLE control
frmMyForm.oleObject.Height = 50  && OLE control height

frmMyForm.Show  && Display the Form

frmMyForm.oleObject.DoVerb(-1)  && -1 for Edit

READ EVENTS  && Start event processing

DEFINE CLASS oleExcelObject as OLEControl
   OleClass ="Excel.Sheet"  && Server name
   DocumentFile = "C:\EXCEL\BOOK1.XLS"  && This file must exist 
ENDDEFINE

DEFINE CLASS cmdMyCmdBtn AS CommandButton  && Create Command button
   Caption = '\<Quit'  && Caption on the Command button
   Cancel = .T.  && Default Cancel Command button (Esc)
   Left = 125  && Command button column
   Top = 210  && Command button row
   Height = 25  && Command button height

   PROCEDURE Click
      CLEAR EVENTS  && Stop event processing, close form
ENDDEFINE

See Also

Reference

OLE Container Control Properties, Methods, and Events

ActiveX Controls Overview

APPEND GENERAL Command

CREATE FORM Command

CREATE CLASS Command

CREATEBINARY( ) Function

DEFINE CLASS Command

MODIFY GENERAL Command

OLE Bound Control

Other Resources

Objects, Collections, and Classes