Sub OnDragDrop(Sender: Object; Args: IDragEventArgs);
Begin
//set of operators;
End Sub OnDragDrop;
Sender. Parameter that returns the component, generated an event
Args. Parameter that allows to determine the event parameters.
The OnDragDrop event occurs for a component if a user drops a dragged object over it.
The objects can be dragged from other applications.
This is an example for the Memo component whose 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 performed on 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 launching 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 like that:
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 icon references is recorded to the Memo component when Drag&Drop an icon.
See also: