Author: Jonas Bilinkevicius
I would like to select text in a TRichEdit control, then drag and drop the text on
another (non TRichEdit) component (ie. TEdit or TMemo). Simulating this behavior
would be fine. The drag- related events are not firing when I drag text, so I
assume the drag and drop behavior is embedded in the Windows control. But I don't
see any drag-related messages in the Windows SDK online help.
Answer:
I've got a unit "uGenDragDrop", that implements IDropTarget (amongst others), and
allows you to easily add OLE Drag and Drop support to any Delphi component (i.e.
allow you to drag and drop not only within a Delphi application, but also in and
out of Delphi applications).
Here is a snippet of code that implements OLE drop support for a TMemo on a form.
1 uses2 uGenDragDrop;
3 4 procedure TForm1.FormCreate(Sender: TObject);
5 begin6 DTMemo := TDropTarget.Create(Memo1);
7 DTMemo.AddFormat(CF_TEXT, [asComplete], [meGlobMemory]);
8 end;
9 10 procedure TForm1.Memo1DragOver(Sender, Source: TObject; X, Y: Integer;
11 State: TDragState; var Accept: Boolean);
12 begin13 Accept := TRUE;
14 end;
15 16 procedure TForm1.Memo1DragDrop(Sender, Source: TObject; X, Y: Integer);
17 begin18 Memo1.Lines.Add((Source as TStorageMedium).GetText);
19 end;