wideman-one 
Last edit: 05-03-17 Graham Wideman

Delphi

GWDragSource unit and GWDragDemo code
Article created: 98-07-26

Introduction

This page describes the main features of the GWDragSource unit, and the GWDragDemo application code.

GWDragDemo Application Architecture, How GWDragSource Fits In

The diagram below shows the basic model.

GWDragDemo_Arch.GIF (22574 bytes)

The basic idea is that main apparatus that deals with COM is located in GWDragSource.PAS, and can be used as-is in a variety of applications.  The piece that's specific to a particular app can inherit the basics and override selected functions for that app's needs.   This is demonstrated in the GWDragDemo application, which uses that GWDragSource.PAS unit, and places all the app-specific drop functionality in DragDemoAppInterface.PAS.

GWDragSource.PAS implements a number of objects:

Finally, all the COM objects inherit from TGWMonInterfacedObject and consequently can cooperate with the monitoring apparatus in GWMonOLE.pas. This can be omitted if not needed.

Details

TGWDragAppInterface

Initialization and Services to Application
constructor Create(
  AOwner: TForm; 
  UseMonitor: Boolean
); virtual;
Call in FormCreate, supply Form as AOwner.  UseMonitor = true to invoke monitoring on COM objects; false causes monitoring to be ignored.
function DoDragDrop(
  dwOKEffects: Longint; 
  var dwEffect: Longint
): HResult; virtual;
Call this to initiate a Drag.  
dwOKEffects tells drag effects permitted (see RTL source, ActiveX.pas or OLE2.pas for DROPEFFECTs). 
dwEffect returns effect actually requested.
property fm_OLEMonitor:
  Tfm_OLEMonitor
Access to fm_OLEMonitor.   Main functions needed will be Show, and DockMe.
Drag Object Delegation Functions. Override these to provide app-specific drag behavior. Without writing any code, the default implementation, will at least allow your app to source drags,  using dummy data.  See demo source code for examples on how to use. Also documented in OLE.Hlp supplied with Delphi.
Delegated from TGWDropSource
function QueryContinueDrag(fEscapePressed: BOOL; grfKeyState: Longint): HResult; virtual;
function GiveFeedback(dwEffect: Longint): HResult; virtual;
Delegated from TGWDragDataObject
function QueryGetData(const formatetc: TFormatEtc): HResult; virtual;
function GetData(const formatetc: TFormatEtc; var medium: TStgMedium): HResult; virtual;
Delegated from TGWDragEnumFormatEtc
function FormatCount: integer; virtual;
procedure FormatEtc(N: integer; var formatetc: TFormatEtc); virtual;
Drag Helper functions
function EffectString(dwEffect: longint): string;
function KeyStateString(grfKeyState: longint): string;

Go to:  Drag Demo Intro Page, or  wideman-one