Make the implementation of WMLButtonDown look like this:
procedure TMyMemo.WMLButtonDown(var Message: TWMLButtonDown);
var
Ch : Integer;
begin
if SelLength > 0 then begin
Ch := LoWord(Perform(EM_CHARFROMPOS,0,
MakeLParam(Message.XPos,Message.YPos)));
LastSelStart := SelStart;
LastSelLength := SelLength;
if (Ch >= SelStart) and (Ch <= SelStart+SelLength-1) then
BeginDrag(True)
else
inherited;
end
else
inherited;
end;
Now, install this component into a package, start a brand new project
in Delphi 3 and drop two TMyMemos down.
Make them both have an OnDragOver event handler looking like this:
procedure TForm1.MyMemo1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := Source is TMyMemo;
end;
Make them both have an OnDragDrop event handler looking like this:
procedure TForm1.MyMemo1DragDrop(Sender, Source: TObject;
X, Y: Integer);
var
Dst, Src : TMyMemo;
Ch : Integer;
Temp : String;
begin
Dst := Sender as TMyMemo;
Src := Source as TMyMemo;
Ch := LoWord(Dst.Perform(EM_CHARFROMPOS,0,MakeLParam(X,Y)));
if (Src = Dst) and (Ch >= Src.LastSelStart) and
(Ch <= Src.LastSelStart+Src.LastSelLength-1) then
Exit;
Launch the app and put some text into the memos, and watch what
happens as you drag and drop inbetween the two memos, or even drag
and drop text from one location in one memo component to another
location in the same memo component.