OLE Drag and Drop Sample Applications
Each of the following links displays the source code (project source, form Pascal or C++ source and form DFM source in text format) for a sample application that uses the UnitOOPS OLE Drag and Drop Components. Examples are included for both Delphi and C++Builder. They are all installed along with the components. They are reproduced here to allow you to get a feel for how the components work, without having to download and install them.
Note On the page for each individual sample application, there are intra-page links to the project source, the form source, and the form DFM source. To convert the form DFM source (which we have displayed as text) to a usable DFM file, you should save it with a .txt extension (e.g., fmRTFTest.txt) and then
run e.g.,
<your Delphi or C++Builder folder>\bin\convert fmRTFTest.txt
which will reconstruct fmRTFTest.dfm.
- New! Discriminate among various kinds of files and shortcuts (DiscriminateShortcutsTest.dpr) [Delphi]
Demonstrates how to discriminate, during a drop, among a file, a URL, a URL contained in an Internet Explorer shortcut, a shell shortcut, etc. This allows you to act on the drop without special-case code.
- Updated! Accepting drops of messages from Outlook, Outlook Express, Netscape and Eudora (EMailTest.dpr) [Delphi]
Demonstrates accepting drops of e-mail and news messages from Outlook Express and Netscape (Messenger or Collabra),
Outlook (message and attachments), and Eudora Pro 4.x. The messages are kept in a combination TListView/TMemo two-pane window, not unlike Outlook Express's and Netscape's own user interfaces. In order to give reasonable text display in a simple memo, HTML messages are massaged to remove tags. Also, demonstrates some useful TStringList tricks for processing e-mail headers, as well as extracting data from more unusual storage media like IStorage and IStream.
- Updated! Dragging and creating multiple files (FileContentsTest2.dpr) [Delphi]
Demonstrates dragging content to be dropped in Explorer as more than one file. It also shows how to delay-render formats using the OnRenderCustomFormat event so you only have to provide the actual data when requested, and how to drop content into a named file in an Explorer folder.
- Updated! Dragging URLs from an application to a browser or the desktop (DragURLTest.dpr) [Delphi]
Demonstrates dragging URLs to Netscape or Internet Explorer from an application. Also shows how you can drag a URL and drop a shortcut on the desktop (or any folder in Windows Explorer).
- Updated! Dragging multiple custom formats (CustomTest2.dpr) [Delphi]
Demonstrates dragging multiple data formats simultaneously, using the CustomFormatData property of TUOTextSource. Also demonstrates delayed rendering of custom data formats (i.e., the data is only made available if it is requested by the drop target. In particular, shows how to drag files and shortcuts from your application to Explorer.
- Dragging DIB's with delayed rendering (DelayRenderDIBTest.dpr) [Delphi]
Demonstrates dragging device-independent bitmaps from your program into another application. Uses delayed rendering, i.e., the data is only actually placed in memory if and when a drop occurs on an application that requests the data.
- Dragging JPEG images (DragJPEGTest.dpr) [Delphi]
Demonstrates dragging from a TImage that contains a JPEG image to another application, using the TUOGraphicSource component..
- Dragging arbitrary items from Outlook (OutlookTest3.dpr) [Delphi]
Demonstrates dragging messages, appointments, contacts, etc. from Microsoft Outlook into a TListView in your own application. Uses Outlook's automation interface to re-open the items when double-clicked.
- Dragging with different mouse buttons (MouseButtonTest.dpr) [Delphi]
Demonstrates dragging with mouse buttons other than the left mouse button. You can drag different content (or the same) depending on which of the mouse buttons initiates the drag. It's also very simple to ensure than every mouse button does the same drag operation, if desired.
- Accepting drops of OLE object links and copies (EmbedTest.dpr) [Delphi]
Demonstrates accepting drops of OLE objects either linked or copied, onto a TOleContainer. For example, drop a selection from Word onto this application and you get a "live" or linked version of the document: change the document in Word and it automatically changes in your linked version, etc. Alternatively, drop with the "copy" option selected, and you get a new copy of that object. Objects can be edited in-place using the functionality of the TOleContainer.
Additionally, we demonstrate building the verb menu for the OLE object manually (as opposed to using auto-activation) so we can trap for OLE exceptions.
Finally, we show how to save the OLE object contained in the TOleContainer to a file, prompting with a TSaveDialog filled in with the correct default extension, file filter and file type.
The example also contains a demonstration of the standard Delphi "hack" to surface a protected event (OnDblClick, which TOleContainer does not surface) without having to write a descendant component. As it turns out, the bulk of this (still short) example is devoted to the verb menu handling!
- Accepting drops on specific nodes of a TTreeView (TreeViewTest.dpr) [Delphi]
Demonstrates accepting drops only on specific nodes of a TTreeView. The cursor correctly shows the drop/no-drop indication depending on the node.
- Drags of custom content into Explorer folders or desktop (FileContentsTest.dpr) [Delphi]
Demonstrates dragging custom content into Explorer. You can drag any binary data and have it saved into a file name of your choosing in whatever folder of Explorer (including the desktop) it's dropped on. This updated version does not require the use of temporary files.
- File drags to, and shortcut drags from a list view (FileTest.dpr) [Delphi]
Demonstrates accepting drops of files from Explorer and other file sources onto a TListView. All file properties are displayed (icon, display name, file name, file size, file type, file attributes) in the same format used by Explorer itself. Both large and small icons are rendered using the system image lists, and the TListView ViewStyle can be manipulated using a set of radio buttons. You can drag shortcuts to one or more files from the TListView onto the desktop (or Explorer) or any other drop target that accepts shortcuts. A less sophisticated C++Builder example is given below.
- Manipulating clipboard formats (ClipboardTest.dpr) [Delphi]
Demonstrates manipulating "fancy" clipboard formats using the helper functions in the uoUtil unit. While this is not directly related to drag-and-drop, the universal data transfer mechanism underlies both, so there are many concepts in common. We show the specific example of putting file names in the clipboard so that the shell (Explorer) will offer the choice to paste them, or paste them as shortcuts. The converse - getting file names from the clipboard, put there by a copy operation in the shell - is also demonstrated.
- Dragging live DDE links to MS Word (uoSource.dpr) [Delphi]
Demonstrates dragging content from an application to be dropped as a live DDE link in MS Word. Works around a bug whereby such links can disconnect prematurely under Windows NT versions prior to SP4, by using a combination of non-auto-updating links and OLE automation. Also shows how to drag rich text format (RTF) snippets into MS Word, in this case the RTF to code a specific macro.
Finally, demonstrates how a drag source can reject an incipient drop on a given target by looking at the window class of the window under the mouse in the TUOTextSource.OnBeforeDrop event. Normally a drop source should be agnostic about the identity of the drop target, except for the formats that the target should accept. This is a good counter-example of a situation where the drop source needs to know more. In particular, the technique allows us to drop the RTF on MS Word, but to cancel attempts to drop the RTF on WordPad (which understands RTF, but not this macro).
- Manipulating the drop effects in a drop target (DropEffectTest.dpr) [Delphi]
Demonstrates displaying and manipulating drop effects in a drop target, when content is dragged over it. By drop effect, we mean "move", "copy" or "link", and the accompanying cursor changes. Even if a drop source is attempting to carry out a copy, e.g., the drop target can force a move (or even ignore a given drop effect completely). This example shows off the properties AvailableDropEffects and OverrideDropEffects[] that were added to TUOTextTarget and TUOGraphicTarget as of Version 1.26.
- "Self-avoiding" drags to/from a TRichEdit (RichEditTest2.dpr) [Delphi]
Demonstrates dragging to/from a plain text rich edit control. Although TRichEdit handles drag and drop natively, sometimes you need to override the drag and drop behavior for other purposes. In this example, we handle the dragging and dropping ourselves, so we can prevent drag and drop within the TRichEdit.
- Simple (RTFTest.dpr) [Delphi]
Demonstrates accepting drops of Microsoft Rich Text Format (RTF) or plain text in a simple memo. This is just about the simplest possible demo you could write. There is a single event handler for the OnDrop event of the TUOTextTarget, with one one crucial line of code (which adds the dropped text to the TMemo).
- Comprehensive (UODDTest.dpr) [Delphi]
The "kitchen sink" demo application, designed to showcase almost all of the features of the components. It demonstrates, using a tabbed dialog interface, drag and drop of both text and graphics between applications, as well as various user feedback techniques. There are examples here of dragging text to or from TListBox, TListView, TTreeView and TMemo controls, and dragging images to and from TImage components, as well as run-time changes in the properties of the components based on user input. If you don't have another drag and drop application available (hint: everyone should have WordPad, which implements drag and drop) such as Word, Excel, Internet Explorer, Netscape Navigator, etc., you can run two instances of uoddtest and drag and drop between them.
- Fancy feedback (MemoTest.dpr) [Delphi]
Demonstrates using the components' events to give sophisticated user feedback. Specifically, this is a form containing a simple TMemo which accepts text drops. During the drop operation, the TMemo's caret follows the drag and the status bar displays "Move to where?" or "Copy to where?" depending on the drop effects, just as Microsoft Word does it. Also shows how to handle character positioning in TMemo controls.
- URL links (URLTest.dpr) [Delphi]
Demonstrates accepting URL drags from Netscape or Internet Explorer into a TListView.
- Rich edit manipulations (RichEditTest.dpr) [Delphi]
Demonstrates accepting rich text format (RTF) into a TRichEdit. Makes use of a utility function, AddContentToRichEdit, in the uoUtil unit, which encapsulates the EM_STREAMIN message.
- Custom format drags (CustomTest.dpr) [Delphi]
Demonstrates dragging and dropping custom formats using TUOTextSource and TUOTextTarget. You can encode your information (either binary or text) as a string and pass it between applications using a private format. This example demonstrates passing a floating point (double) number between two applications using a user-choosable clipboard format name.
- Detecting available data formats (CustomTest3.dpr) [Delphi]
Demonstrates the TUOTextTarget component's access to the data object being dragged over it. Drag from any drag source over this applications form to see a listing of all data formats that can be supplied by the drag source (for a very impressively long list, try dragging from MS Excel!)
- Accepting multiple custom formats (CustomTest4.dpr) [Delphi]
Demonstrates how a TUOTextTarget can accept multiple data formats from the same drag source.
- Dragging to a string grid (StringGridTest.dpr) [Delphi]
Demonstrates accepting text into a TStringGrid, typically dragged from MS Excel. If the dropped cells extend beyond the grid, enough new rows and columns are added to accomodate the data. Also shows how to scroll the string grid and give feedback for a better user interface.
- Dragging attachments from MS Outlook (OutlookTest.dpr) [Delphi]
Demonstrates accepting drops of e-mail attachments, particularly from MS Outlook, which provides the data in an unusual format (as bytes on an IStream interface, combined with a file group descriptor to supply the names).
- Viewing available data formats (Available.dpr) [Delphi]
Demonstrates detecting the data formats available when dragging over a TUOTextTarget (or TUOGraphicTarget) in a simpler way than the lower-level technique in the example above.
- Using custom drag cursors (CursorTest.dpr) [Delphi]
Demonstrates using custom drag cursors when dragging content from a TUOTextSource. While one can simply use cursors from resources, this example dynamically constructs drag cursors to represent files dragged from a file list box, including the correct OLE cursor and the file name and small icon. This version works only under Windows NT, since Windows 95 will not permit cursors to be bigger than the standard size (see CursorTest2.dpr below for a more general solution)
- Using custom drag cursors (CursorTest2.dpr) [Delphi]
Demonstrates using custom drag cursors when dragging content from a TUOTextSource. While one can simply use cursors from resources, this example dynamically constructs drag cursors to represent files dragged from a file list box, including the correct OLE cursor and the file name and small icon. This version works on all Win32 platforms, and uses the imagelist functions to manage the drag images (see CursorTest.dpr above for a simpler, NT-specific solution).
- New! Dragging files from a C++Builder application (CPPDragFileTest.cpp) [C++Builder]
Demonstrates the use of TUOTextSource for dragging files and shortcuts to the desktop or Explorer. You can choose, using checkboxes, whether to allow any or all of copy, move and link (shortcut). This is effectively the inverse of the CPPFileTest application described below.
- Accepting URLs, text, pictures in C++Builder (CPPTest.cpp) [C++Builder]
Demonstrates the use of TUOTextTarget (for text and URLs) and TUOGraphicTarget to accept dropped text and graphic data. Accepts text and URLs in a TMemo, and images dragged onto a TImage.
- URL links (CPPURLTest.dpr) [C++Builder]
Demonstrates accepting URL drags from Netscape or Internet Explorer into a TListView. Essentially identical to the Delphi "URL links" example above
- Drags to/from TRichEdit (CPPRichEditDrag.dpr) [C++Builder]
Demonstrates dragging to and from a TRichEdit. Test by dragging between this application and, e.g. MS-Word or WordPad.
- Drag files to a TListView (CPPFileTest.dpr) [C++Builder]
Demonstrates dragging files from Explorer or another file drag source to a TListView. Displays the file path, size, etc. A similar, more sopisticated, Delphi example is shown above.
- Dragging attachments from MS Outlook (CPPOutlookTest.dpr) [C++Builder]
Identical to the Delphi version above, but written in C++Builder.
Back to the UnitOOPS Software home page
Last modified: Friday, March 23, 2001