http://xuhao23.myetang.com/zl/delphi2zn.zip
Delphi2.0 高级程序设计指南 1.6M 阅读:IE 下载:本站 镜像 2001.3.6  
简介:第一章 Delphi快速入门;第二章 Delphi 面向对象的编程方法;第三章 字符串列表及应用;第4章 文本编辑器的设计;第五章 Delphi图形图像编程;第六章 文件管理;第七章 剪贴板和动态数据交换;第八章 对象的链接与嵌入;第九章 Delphi 拖放(DragDrop)编程;第十章 动态链接库(DLLs)编程;第十一章 Delphi应用程序的Help应用;第十二章 异常处理与程序调试;第十三章 Delphi开发数据库应用程序概述;第十四章 简单数据库应用的创建及MASTAPP介绍;第十五章 数据访问部件的应用及编程;第十六章 数据浏览部件的应用及编程;第十七章 SQL编程;第十八章 Delphi客户/服务器应用开发;第十九章 Delphi 自定义部件开发;第二十章 开发Delphi对象式数据管理功能。
 
这本书虽然老了点,但是对于你的问题还是有帮助的,里面有专门关于拖放编程的教程

解决方案 »

  1.   

    用以下方法实现:
      var CurentDirList: Array[0...25] of string[70];   在DirectoryOutline的OnChange事件中:procedure TFMForm.DirectoryOutlineChange(Sender: TObject); begin CreateCaption; FileList.clear; FileList.Directory := DirectoryOutline.Directory; FileList.Update; CurrentDirList[DriveTabSet.TabIndex] := DirectoryOutline.Directory; FileManager.DirectoryPanel.Caption := DirectoryOutline.Directory; end;  
      由于DriveTabSet在响应OnDragDrop事件前先响应OnClick事件,并由该事件激
    发DirectoryOutline的Onchange事件,因而可保证在任何时候OnDragDrop事件中用
    到的CurrentDirList数组项不为空字符串。  2.如何保证移动、拷贝与子窗口的无关性?  在这里一个关键问题是我们判断源控件时是用is操作符进行类型检查:   If Source is TFileList then …  如果我们用下面的语句:    If Source = FileList then   …  则移动、拷贝操作将限制在本子窗口范围内。  当解决了上述问我们的工作就只是遵循拖放的一般开发步骤,按步就班来完成了。  1.FileList开始拖动操作procedure TFMForm.FileListMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Button = mbLeft then with Sender as TFileListBox do begin if ItemAtPos(Point(X, Y), True) >= 0 then BeginDrag(False); end; end;   ItemAtPos用来检查当前是否有文件存在。而BeginDrag方法传递参数False,允许FileList单独处理鼠标事件而并不开始拖动。事实上这种情况是大量存在的。    2.DirectoryOutline、DriveTabSet决定是否能接受拖动的就地放下。
    procedure TFMForm.DirectoryOutlineDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin if Source is TFileListBox then Accept := True; end; 
    procedure TFMForm.DriveTabSetDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); var PropPos: Integer; begin if Source is TFileListBox then with DriveTabSet do begin PropPos := ItemAtPos(Point(X,Y)); Accept := (PropPos > -1) and (PropPos < Tabs.Count); end; end; 
      DirectoryOutline是无条件的接受,而DriveTabSet需检查是否是合法的标签。    3.拖动放下的响应  DirectoryOutline的拖动放下用于实现文件移动功能。程序中调用ConfirmChange 事件
    处理过程,目标路径由DirctoryOutline.Items[GetItem(X,Y)].FullPath来得到。
    procedure TFMForm.DirectoryOutlineDragDrop(Sender, Source: TObject; X, Y: Integer); begin if Source is TFileListBox then with DirectoryOutline do begin ConfirmChange('Move',FileList.FileName, Items[GetItem(X, Y)].FullPath); end; end;   DriveTabSet的拖动放下用于实现文件拷贝功能。程序中把当前位置转化为相应的驱
    动器号,目标路径由CurrentDirList[DriveTabSet.TabIndex]获得。procedure TFMForm.DriveTabSetDragDrop(Sender, Source: TObject; X,Y: Integer); var APoint: TPoint; begin APoint.X := X; APoint.Y := Y; DriveTabSet.TabIndex := DriveTabSet.ItemAtPos(APoint); if Source is TFileListBox then with DriveTabSet do begin if CurrentDirList[TabIndex] <> '' then ConfirmChange('Copy',TheFilename,CurrentDirList[TabIndex]); end; end; 
      4.FileList响应拖动结束,更新文件列表procedure TFMForm.FileListEndDrag(Sender, Target: TObject; X, Y: Integer); begin if Target <> nil then FileList.Update; end; 
      

  2.   

    用以下方法实现:
      var CurentDirList: Array[0...25] of string[70];   在DirectoryOutline的OnChange事件中:procedure TFMForm.DirectoryOutlineChange(Sender: TObject); begin CreateCaption; FileList.clear; FileList.Directory := DirectoryOutline.Directory; FileList.Update; CurrentDirList[DriveTabSet.TabIndex] := DirectoryOutline.Directory; FileManager.DirectoryPanel.Caption := DirectoryOutline.Directory; end;  
      由于DriveTabSet在响应OnDragDrop事件前先响应OnClick事件,并由该事件激
    发DirectoryOutline的Onchange事件,因而可保证在任何时候OnDragDrop事件中用
    到的CurrentDirList数组项不为空字符串。  2.如何保证移动、拷贝与子窗口的无关性?  在这里一个关键问题是我们判断源控件时是用is操作符进行类型检查:   If Source is TFileList then …  如果我们用下面的语句:    If Source = FileList then   …  则移动、拷贝操作将限制在本子窗口范围内。  当解决了上述问我们的工作就只是遵循拖放的一般开发步骤,按步就班来完成了。  1.FileList开始拖动操作procedure TFMForm.FileListMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Button = mbLeft then with Sender as TFileListBox do begin if ItemAtPos(Point(X, Y), True) >= 0 then BeginDrag(False); end; end;   ItemAtPos用来检查当前是否有文件存在。而BeginDrag方法传递参数False,允许FileList单独处理鼠标事件而并不开始拖动。事实上这种情况是大量存在的。    2.DirectoryOutline、DriveTabSet决定是否能接受拖动的就地放下。
    procedure TFMForm.DirectoryOutlineDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin if Source is TFileListBox then Accept := True; end; 
    procedure TFMForm.DriveTabSetDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); var PropPos: Integer; begin if Source is TFileListBox then with DriveTabSet do begin PropPos := ItemAtPos(Point(X,Y)); Accept := (PropPos > -1) and (PropPos < Tabs.Count); end; end; 
      DirectoryOutline是无条件的接受,而DriveTabSet需检查是否是合法的标签。    3.拖动放下的响应  DirectoryOutline的拖动放下用于实现文件移动功能。程序中调用ConfirmChange 事件
    处理过程,目标路径由DirctoryOutline.Items[GetItem(X,Y)].FullPath来得到。
    procedure TFMForm.DirectoryOutlineDragDrop(Sender, Source: TObject; X, Y: Integer); begin if Source is TFileListBox then with DirectoryOutline do begin ConfirmChange('Move',FileList.FileName, Items[GetItem(X, Y)].FullPath); end; end;   DriveTabSet的拖动放下用于实现文件拷贝功能。程序中把当前位置转化为相应的驱
    动器号,目标路径由CurrentDirList[DriveTabSet.TabIndex]获得。procedure TFMForm.DriveTabSetDragDrop(Sender, Source: TObject; X,Y: Integer); var APoint: TPoint; begin APoint.X := X; APoint.Y := Y; DriveTabSet.TabIndex := DriveTabSet.ItemAtPos(APoint); if Source is TFileListBox then with DriveTabSet do begin if CurrentDirList[TabIndex] <> '' then ConfirmChange('Copy',TheFilename,CurrentDirList[TabIndex]); end; end; 
      4.FileList响应拖动结束,更新文件列表procedure TFMForm.FileListEndDrag(Sender, Target: TObject; X, Y: Integer); begin if Target <> nil then FileList.Update; end; 
      

  3.   

    procedure TForm1.DirectoryOutline1Change(Sender: TObject);
    begin
        FileListBox1.Directory :=DirectoryOutLine1.Directory ;
        FileListBox1.Update;
    end;procedure TForm1.FileListBox1MouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      if Button = mbLeft then
      with Sender as TFileListBox do
      begin
        if ItemAtPos(Point(X, Y), True)  >=  0 then //检查当前是否有文件存在
            BeginDrag(False);  //允许FileList单独处理鼠标事件而并不开始拖动
      end;
    end;procedure TForm1.DirectoryOutline1DragOver(Sender, Source: TObject; X,
      Y: Integer; State: TDragState; var Accept: Boolean);
    begin
         if Source is TFileListBox then
        Accept := True;
    end;procedure TForm1.FileListBox1EndDrag(Sender, Target: TObject; X,
      Y: Integer);
    begin
      if Target <> nil then FileListbox1.Update;
    end;procedure TForm1.DirectoryOutline1DragDrop(Sender, Source: TObject; X,
      Y: Integer);
    var
        sSource,sDest,sFileName,sTemp:String;
    begin
        sSource:='';
        sDest:='';
        if DirectoryOutline1.GetItem(x,y)>0 then  //鼠标放下处有目录存在
        begin
            sSource:=FileListbox1.fileName;//取源文件名(含路径)
            sFileName:=extractfilename(sSource);//不含路径
            sTemp:= DirectoryOutline1.Items[DirectoryOutline1.GetItem(x,y)].FullPath+'\'+sFileName;
            //也许是Delphi的BUG吧(或者是C语言的目录习惯),sTemp居然等于c:\\chenhu2,所以要转换为 c:\chenhu2
            sDest:=copy(sTemp,1,2)+Copy(sTemp,4,Length(sTemp)-3);
    //        edit1.Text:=sSource;
    //        Edit2.Text:=sDest;
            if   MessageDlg('移动文件,从'+sSource+' 到'+sDest ,mtConfirmation,[mbYes,mbNo],0)=mrYes then
            begin
                if MoveFile(PChar(sSource),PChar(sDest)) then    //uses Shellapi
                    Showmessage('移动文件成功')
                else
                    Showmessage('移动文件失败');
            end;    end;
    end;