unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, StrUtils, Buttons, ExtCtrls, Math;
type
TfrmDragDrop =
class(TForm)
btnClose: TButton;
edtDrag1: TEdit;
edtDrag2: TEdit;
procedure btnCloseClick(Sender: TObject);
procedure edtDrag1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure edtDrag2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState;
var Accept: Boolean);
procedure edtDrag2DragDrop(Sender, Source: TObject; X, Y: Integer);
procedure edtDrag1StartDrag(Sender: TObject;
var DragObject: TDragObject);
procedure edtDrag1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
SelectedStart, SelectedEnd: Integer;
InDragMode: Boolean;
public
{ Public declarations }
end;
var
frmDragDrop: TfrmDragDrop;
implementation
{$R *.dfm}
procedure TfrmDragDrop.edtDrag1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
CursorPos: integer;
begin
CursorPos := edtDrag1.Perform(EM_CHARFROMPOS, 0, X);
// Cursorstelle
if InDragMode
then
edtDrag1.EndDrag(False);
if (CursorPos >= SelectedStart)
and
(CursorPos <= SelectedEnd)
then
if InDragMode
then
InDragMode := False
else begin
InDragMode := True;
edtDrag1.BeginDrag(False, 10);
end;
end;
procedure TfrmDragDrop.edtDrag1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if not InDragMode
then begin
SelectedStart := edtDrag1.SelStart;
SelectedEnd := SelectedStart + edtDrag1.SelLength;
end;
end;
procedure TfrmDragDrop.edtDrag1StartDrag(Sender: TObject;
var DragObject: TDragObject);
begin
EdtDrag1.SelStart := SelectedStart;
EdtDrag1.SelLength := SelectedEnd - SelectedStart;
InDragMode := True;
end;
procedure TfrmDragDrop.edtDrag2DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
EdtDrag2.Text := EdtDrag1.SelText;
end;
procedure TfrmDragDrop.edtDrag2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState;
var Accept: Boolean);
begin
Accept := True;
end;
procedure TfrmDragDrop.FormCreate(Sender: TObject);
begin
SelectedStart := -1;
SelectedEnd := -1;
InDragMode := False;
end;
procedure TfrmDragDrop.btnCloseClick(Sender: TObject);
begin
Close;
end;
end.