Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

Object

This keyword lets you dig inside an OLE Container control to talk to the actual ActiveX control inside. Most of the time, though, you don’t need it.

Usage

oleContainer.Object.Property = uValue
uValue = oleContainer.Object.Property
oObject = oleContainer.Object
oleContainer.Object.Method()

To put an ActiveX control (formerly known as an OLE control) on a form, you first drop an OLE Container control (one of the VFP base classes) onto the form, then choose the appropriate ActiveX control. If you prefer and you’ve registered the control with VFP, you can choose the control from the ActiveX controls toolbar, but it still brings an OLE Container with it. Both the OLE Container and the ActiveX control have properties and methods.

When you’re writing code, you can almost always ignore the fact that there are two levels of objects here, and just refer to the ActiveX control’s PEMs as if they belong to the OLE Container. However, in a few rare cases, this approach doesn’t work—that’s when you need the Object keyword. Stick it after the reference to the OLE Container to make sure you’re addressing the ActiveX control, not its container.

The most obvious place that Object is needed is when you’re actually trying to get an object reference to the ActiveX control. For example, the ActiveX TreeView control uses an ActiveX ImageList. You have to set the TreeView’s ImageList property in code, giving it a reference to the ImageList you’ve already created. In this case, the Object keyword is required.

Example

* Say you've put an ImageList on the
* form and called its OLE Container
* oleImageList. To assign this
* ImageList to a Treeview in an
* OLE Container called oleTree, use:
ThisForm.oleTree.ImageList = ThisForm.oleImageList.Object

See Also

OLEControl