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.

DataObject

This COM class is one of the keys to the power of OLE Drag and Drop. It contains the data being dragged in various formats. Because this is not a native VFP class, it can’t be subclassed in VFP. The object exposes only methods, no properties, and has no events of its own. Let’s point out right up front, too, that data objects appear only in OLE Drag and Drop operations, not in native VFP drag and drop. That means, among other things, that any references to “drag source” or “drop target” or any of the other drag and drop terms below mean OLE Drag and Drop. None of this stuff applies to the native drag and drop.

When an OLE Drag and Drop operation begins, a data object is created. Information about the source data is put into the data object, which is then passed to a number of the OLE Drag and Drop methods. You can both access and modify the data in the data object. You can even populate it with your own custom data.

The data object accepts data in many different formats. For any one drag and drop operation, it can contain the same data in more than one format. One common, easy-to-understand format is text. If you highlight some text in a control and start dragging, the data object contains that text in its format numbered 1 (which means “text”). If the drag source is a VFP control, the data object also contains data in the “VFP Source Object” format. That one offers you a reference to the drag source. A number of other formats are built in to handle things like lists of files, non-character data, and so forth.

However, if none of the formats is what you need, you can also create your own and put whatever data you want into it, even if it has nothing whatsoever to do with the drag source. (Actually, you can do that with the built-in formats, too. Want to confound your user? Set up a drag source that automatically replaces its text data with the string “Sorry, Charlie!”)

The data object exists only for the length of the drag and drop operation. As soon as the mouse button comes up and any drop is processed, the data object self-destructs.

You can't watch the data object in the debugger. That's partly because it's a COM object, but much more because there's no way to get to the debugger while the various methods that let you touch the data object are running. You can't put breakpoints in them or use SUSPEND (well, you can, but it doesn't work). Even if an error occurs in those methods, you can't get to the debugger.

There are only a few methods available for working with the data object, but they give you everything you need to do the job.

Method

Purpose

ClearData

Remove all data and formats from the data object.

GetData

Retrieve data in a specified format from the data object.

GetFormat

Determine whether the data object contains data in a specified format.

SetData

Place data in a specified format into the data object.

SetFormat

Indicate that the data object contains data in a specified format.

Example

* See the various OLE drag and drop methods, as well as
* the methods listed above for examples of using the data object

See Also

ClearData, GetData, GetFormat, OLE drag and drop, OLEDragDrop, OLEDragOver, OLESetData, OLEStartDrag, SetData, SetFormat