新建一工程,在Form上放置一个Label1控件,一个DropTextTarget1控件,一个DataFormatAdapter1
控件。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, DragDrop, DropTarget, DragDropText;
type
TForm1 = class(TForm)
Label1: TLabel;
DropTextTarget1: TDropTextTarget;
DataFormatAdapter1: TDataFormatAdapter;
procedure DropTextTarget1Drop(Sender: TObject; ShiftState: TShiftState;
APoint: TPoint; var Effect: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses
DragDropFormats, //注意这里要引用两个单元
DragDropInternet;
procedure TForm1.DropTextTarget1Drop(Sender: TObject;
ShiftState: TShiftState; APoint: TPoint; var Effect: Integer);
begin
if (DataFormatAdapter1.DataFormat <> nil) then
Label1.Caption := (DataFormatAdapter1.DataFormat as TURLDataFormat).URL;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DropTextTarget1.Target := Form1;
DataFormatAdapter1.DataFormatName := 'TURLDataFormat';
DataFormatAdapter1.DragDropComponent := DropTextTarget1;
DataFormatAdapter1.Enabled := true;
end;
end.