OnDragDrop

Syntax

Sub OnDragDrop(Sender: Object; Args: IDragEventArgs);

Begin

//set of operators;

End Sub OnDragDrop;

Parameters

Sender. Parameter that returns the component that has generated the event.

Args. Parameter that enables the user to determine event parameters.

Description

The OnDragDrop event occurs for the component if the user drops a dragged object over it.

Comments

The objects can be dragged from other applications.

Example

This is an example for the Memo component, which implementation allows dragging the text from other applications to the Memo component:

1) Create a form.

2) Place the Memo component named Memo1 on this form (all further operations are executed with this component).

3) Set the AllowDrop property to True.

4) Create the following handler of the OnDragOver event for the Memo1 component:

Sub Memo1OnDragOver(Sender: Object; Args: IDragEventArgs);
Begin
    Args.Effect := DragDropEffects.Copy;
End Sub Memo1OnDragOver;

5. Create the following handler of the OnDragDrop event:

Sub Memo1OnDragDrop(Sender: Object; Args: IDragEventArgs);
Begin
    Memo1.Text := Args.Data 
As String;
End Sub Memo1OnDragDrop;

The text drag from other applications (for example, Microsoft Word) to the Memo component is available after starting the form.

The restriction of this example is that only one line of the text can be dragged. To drag several lines of the text at the same time, the handler of the OnDragDrop event should be modified as follows:

Sub Memo1OnDragDrop(Sender: Object; Args: IDragEventArgs);
Var
    v: Variant;
    i: Integer;
    List: IStringList;
Begin
    Memo1.Clear;
    v := Args.Data;
    If v Is String Then
        Memo1.Text := v As String;
    End If;
    If v Is IStringList Then
        List := v As IStringList;
        For i := 0 To List.Count - 1 Do
            Memo1.Lines.Add(List.Item(i));
        End For;
    End If;
End Sub Memo1OnDragDrop;

Dragging not only text but, for example, shortcuts to the Memo component is available after modification of the OnDragDrop event handler. The file path, to which the shortcut refers, is recorded to the Memo component when dragging and dropping an icon.

See also:

IControl