我想实现:当按下某一BUTTON后出现一个类似OpenDialog打开的界面,当选择某一目录后按确定,关闭该界面,在刚才BUTTON页面上放上一个EDIT,我想把刚才选的路径显示在该EDIT框里,我用了OpenDialog,但好象OpenDialog只能选择文件而不能选择路径,我又用了SelectDirectory函数,但好象他不能选择局域网上的共享目录,不知道该问题该如何解决?还望大家多多指教,谢谢!

解决方案 »

  1.   

    procedure TForm1.Button8Click(Sender: TObject);
    var
    localfname:string;
    begin
    if OpenDialog1.Execute then
    localfname:=OpenDialog1.FileName;
    showmessage(localfname);
    end;
      

  2.   

    if OpenDialog1.Execute then
    edit1.text:=ExtractFilePath(OpenDialog1.FileName);
      

  3.   

    if OpenDialog1.Execute then
    begin
      edit1.text:=ExtractFilePath(OpenDialog1.FileName);//返回文件目录
      edit2.text:=ExtractFileName(OpenDialog1.FileName);//返回文件名
    end;
    选一个吧。
      

  4.   

    Sends CDN_INCLUDEITEM notification messages to the dialog when the user opens a folder.
      

  5.   

    //将全文件名分解程文件名和路径
    ListItem := ListView1.Items.Add;
    ListItem.Caption := ExtractFileName(FileName);
    listitem.ImageIndex:=6;
    ListItem.SubItems.Add(ExtractFilePath(FileName));
    filepath:=extractfilepath(filename);
    showmessage(filepath);
      

  6.   

    或者调用api函数:GetWindowsDirectory().
      

  7.   

    samples页的 TShellTreeView 控件可以实现你的要求。
      

  8.   

    procedure TPub.FileCopyDirectory(sDir, tDir: string; bRecursive: Boolean);
    var
      SearchRec: TSearchRec;
      Status   : Integer;
    begin
      sDir := PathWithSlash(sDir);
      tDir := PathWithSlash(tDir);  Status := FindFirst(sDir + '*.*', faAnyFile, SearchRec);
      try
        while Status = 0 do
        begin
          if bRecursive and (SearchRec.Attr and faDirectory = faDirectory) then
          begin
            if (SearchRec.name <> '.') and (SearchRec.name <> '..') then
              FileCopyDirectory(sDir + SearchRec.name, tDir, bRecursive);
          end else FileCopyFile(sDir + SearchRec.name, tDir + SearchRec.name);      Status := FindNext(SearchRec);
        end;
      finally
        SysUtils.FindClose(SearchRec);
      end;
    end;
      

  9.   

    TPub.FileCopyDirectory该如何调用?还望指教,谢谢!