- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


3192:Implementing Drag and Drop Functionality

KEYWORDS: Drag, Drop, TEdit, Components, Sender, Source AREA: Application Inte

This document describes the process of creating a drag and drop
functionality that could be applied to text items and graphical
objects. Regular text indicates the procedural steps to execute
to achieve the functionality. Text in the parentheses is
explanation and background information.

1. Place the two edit boxes onto your form. {One will serve as
the source for the text that you will drag and drop. The other
will serve as the destination you will drop the text onto.}

2. Select the first edit box and name it SourceEdit by
entering that name in the name property in the Object
Inspector.

3. Select the second edit box and name it SenderEdit. {The
names source and sender are not necessary. They are
suggested because "source" and "sender" are default variables
given to work with in the OnDragOver and OnDragDrop event
procedure code blocks. The source variable is where the
drag operation began, and the sender variable is the control
that was dropped onto. See the help topics related to
messages for further information on this and related topics.}

4. Click the SourceEdit component so it is selected and go to
the Object Inspector. Set its DragMode property to
dmAutomatic.

5.  Select the SenderEdit and go to the events page of the
Object Inspector and double click on the OnDragOver  event.

6. Type exactly what is in the quotes here where the cursor
is between the begin and end statements: "Accept := True;".
{Notice that the Accept variable is supplied for you by
default inside of the OnDragOver event procedure code block.}

7. Now go to the events page of the Object Inspector and
double click on the OnDragDrop event.

8. Type exactly what is in the quotes here where the cursor
is between the begin and end statements:
" SenderEdit.Text := SourceEdit.Text ".

Now if you run the application you will be able to click down
on the SourceEdit component and drag and drop onto the
SenderEdit component.  When you drop onto the SenderEdit it
changes its text to whatever was in the SourceEdit.

        TI



* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile