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.

OLESetData

This event is part of the set of PEMs that gives you total control over what actually gets dropped during OLE Drag and Drop. It lets you determine the data dropped, at the very last minute, just as it’s needed.

Usage

PROCEDURE oObject.OLESetData
LPARAMETERS oDataObject, uFormat

Parameter

Value

Meaning

oDataObject

Object

An object reference to the data being dragged and information about it.

uFormat

Numeric or Character

The data format requested by the drop target.

OLESetData belongs to the drag source. When a drag operation ends with a drop, VFP looks for data that’s compatible with the target and either copies or moves it to the target.

OLESetData gives you a chance to change that data. It fires after any custom code in OLEDragDrop, but before the drop actually takes place. It also fires if the data object’s GetData method is called. (If you do that, be sure to add a NODEFAULT in OLEDragDrop or you end up with double your dropped data.)

In VFP 6, Help says that OLESetData fires when there's no data in the appropriate format. In VFP 7, it also says that OLESetData fires when GetData is executed. Neither statement is completely correct. OLESetData fires whenever it contains code. We're hoping this one is a documentation bug, not a product bug, because we really like the idea of deciding what to drop at the very last minute.

Why would you want to replace the data to drop at the end? Good question. Help suggests that the main reason is to put the data into the DataObject only when it’s needed. The implication is that, when you’re dealing with a lot of data, carrying it around could eat resources.

We can think of times when we want to base the final decision of what to drop on other conditions at the time. You might want to populate the drop target with data fresh from the database by issuing a SQL SELECT when it’s performed. It’s possible the drop might even be the event that creates the data, so perhaps you’ll populate the data object with the primary key. It seems to us that the main condition to check this way is the identity of the drop target. You might want to return different data depending on where it’s going. (For drop targets in VFP, you can use AMouseObj() to find the drop target because, by definition, the mouse must be over the drop target at the time.)

The uFormat parameter indicates which format the target is looking for, so you can take different actions depending on what the target wants.

You might be puzzled by the choice of data types for uFormat. The older formats still retain the numeric values used for clipboard and DDE work, while some of the newer formats tend to have more descriptive text names. Check FoxPro.H for a list of the more common ones (they’re in the Clipboard Format section, and start with CF_ or CFSTR_). Custom formats can also be assigned either a number or a string. (Because character strings tend to convey information while numbers generally don’t, we recommend using them.)

We don’t see ourselves using this event a lot, but we have a feeling that, on those rare occasions where we do need it, it will be invaluable.

Example

* The example for OLEStartDrag shows how to create
* a custom format and add to it. In that example,
* the data is added in OLEStartDrag. But, that line
* could instead occur in OLESetData:
oDataObject.SetData(This.Picture,"Picture")

See Also

DataObject, GetData, GetFormat, OLE drag and drop, OLEDragDrop, SetData