下面是实现拖放的代码,请兄台参考一下:
////////////////////////////////加入数据成员
private
sourceFile,destFile:String;
////////////////////
procedure TForm1.DirectoryListBox1DragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
begin
if Sender<>Source then
Accept:=true
else
Accept:=false;
end;
procedure TForm1.DirectoryListBox1DragDrop(Sender, Source: TObject; X,
Y: Integer);
var pos:TPoint;
index:Integer;
begin
pos.x:=x;
pos.y:=y;
index:=DirectoryListBox1.ItemAtPos(pos,true);
if index<>-1 then
DirectoryListBox1.ItemIndex:=index;
DestFile:=DirectoryListBox1.GetItemPath(index)+'/'+DestFile; //获得目的文件路径和名称
copyfile(PCHAR(SourceFile),PCHAR(DestFile),true); //拷贝文件
end;
procedure TForm1.FileListBox1DragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
begin
sourceFile:=FileListBox1.FileName; //获得元文件路径和名称。
DestFile:=ExtractFileName(sourceFile); //获得文件名称
end;