procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
  node:TTreenode;
  i:integer;
begin
if source is Tfilelistbox then begin
for i:=0 to filelistbox1.SelCount-1 do begin
  node:=treeview1.GetNodeAt(x,y);
//for i:=0 to filelistbox1.SelCount-1 do begin for语句放在这儿,也是运行错误,什么也不显示,treeview里面  filelistbox1.ItemIndex:=i;
   if node=nil then
    treeview1.Items.Add(node,filelistbox1.FileName)
   else
    treeview1.Items.Addchild(node,filelistbox1.FileName);
  end;
  memo1.Lines.Add(filelistbox1.FileName);
end;
end;

解决方案 »

  1.   

    FileListBox的OnMouseDown事件中写了FileListBox.BeginDrag(true)?
      

  2.   

    我的代码是写FileListBox1.BeginDrag(false)的?
      

  3.   

    Delphi syntax:procedure BeginDrag(Immediate: Boolean; Threshold: Integer = -1);C++ syntax:void __fastcall BeginDrag(bool Immediate, int Threshold = -1);DescriptionCall BeginDrag to start a drag operation. BeginDrag is called in application code only when the value of the control抯 DragMode is dmManual. If DragMode is dmAutomatic, BeginDrag is called automatically.If the Immediate parameter is true, the mouse pointer changes to the value of the DragCursor property and dragging begins immediately. If Immediate is false, the mouse pointer doesn't change to the value of the DragCursor property and dragging doesn't begin until the user moves the mouse pointer the number of pixels specified by the Threshold parameter. If the caller passes a Threshold value less than 0 (such as the default value for this parameter), BeginDrag uses the DragThreshold property of the global Mouse variable.
      

  4.   

    下面这样可以设置FileListBox1.DragMode := dmAutomatic;procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
    var
      node,newnode:TTreenode;
      i:integer;
    begin
      if source is Tfilelistbox then
        begin      for i := 0 to FileListBox1.Count - 1 do
            if FileListBox1.Selected[i] then
               begin
               if node=nil then
                    treeview1.Items.Add(node,filelistbox1.FileName)
               else
                    treeview1.Items.Addchild(node,FileListBox1.FileName);
               end;
          memo1.Lines.Add(filelistbox1.FileName);
         end;
    end;
      

  5.   

    cxreal(转身离开的是你) 说的是对的。ttoth12 (borlander) 的代码里的问题就在这一行:
    filelistbox1.ItemIndex:=i;