Monday, April 13, 2015

Drop files on the form (FMX vs VCL)

To enable file drag and drop for the control in VCL one typically need to implement WM_DROPFILES message handler and query file count and names with DragQueryFile WinAPI function.

In FMX there are platform independent OnDragOver and OnDragDrop events can be used to drop both files and controls.

Though there are no such events for TForm published, you can just override form methods:

procedure DragOver(const Data: TDragObject; const Point: TPointF;  var Operation: TDragOperation); override;


procedure DragDrop(const Data: TDragObject; const Point: TPointF); override;
DragOver will be triggered first. Default Operation is TDragOperation.None.

TDragOperation = (None, Move, Copy, Link);

Return something other than None to accept dragged item.

Both methods have file list in Data.Files array

TDragObject = record
    Source: TObject;
    Files: array of string;
    Data: TValue;

Source is control dragged (nil for files). To enable control dragging set its DragMode property to dmAutomatic.

No comments:

Post a Comment