SelectDirectory这个函数是如何用的?(20分)

W

winsock

Unregistered / Unconfirmed
GUEST, unregistred user!
Selectdirectory这个函数是浏览文件夹的,<br>我看了一下帮助文件<br>function SelectDirectory(const Caption: WideString; const Root: string;<br>&nbsp;var Directory: string): Boolean;<br>里面是这样介绍的,可我不大明白<br>const Root: string; 这个是参数是设置什么的?<br>SelectDirectory('标题','dsdds',STR)前一个是标题,后一个是盘符。那中间那个呢?<br>好象不起什么作用呀!<br><br>
 
function SelectDirectory(const Caption: string; const Root: WideString;<br>&nbsp; var Directory: string): Boolean;<br>var<br>&nbsp; WindowList: Pointer;<br>&nbsp; BrowseInfo: TBrowseInfo;<br>&nbsp; Buffer: PChar;<br>&nbsp; RootItemIDList, ItemIDList: PItemIDList;<br>&nbsp; ShellMalloc: IMalloc;<br>&nbsp; IDesktopFolder: IShellFolder;<br>&nbsp; Eaten, Flags: LongWord;<br>begin<br>&nbsp; Result := False;<br>&nbsp; if not DirectoryExists(Directory) then<br>&nbsp; &nbsp; Directory := '';<br>&nbsp; FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);<br>&nbsp; if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc &lt;&gt; nil) then<br>&nbsp; begin<br>&nbsp; &nbsp; Buffer := ShellMalloc.Alloc(MAX_PATH);<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; RootItemIDList := nil;<br>&nbsp; &nbsp; &nbsp; if Root &lt;&gt; '' then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; SHGetDesktopFolder(IDesktopFolder);<br>&nbsp; &nbsp; &nbsp; &nbsp; IDesktopFolder.ParseDisplayName(Application.Handle, nil,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; POleStr(Root), Eaten, RootItemIDList, Flags);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; with BrowseInfo do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; hwndOwner := Application.Handle;<br>&nbsp; &nbsp; &nbsp; &nbsp; pidlRoot := RootItemIDList;<br>&nbsp; &nbsp; &nbsp; &nbsp; pszDisplayName := Buffer;<br>&nbsp; &nbsp; &nbsp; &nbsp; lpszTitle := PChar(Caption);<br>&nbsp; &nbsp; &nbsp; &nbsp; ulFlags := BIF_RETURNONLYFSDIRS;<br>&nbsp; &nbsp; &nbsp; &nbsp; if Directory &lt;&gt; '' then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lpfn := SelectDirCB;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lParam := Integer(PChar(Directory));<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; WindowList := DisableTaskWindows(0);<br>&nbsp; &nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; &nbsp; ItemIDList := ShBrowseForFolder(BrowseInfo);<br>&nbsp; &nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; &nbsp; EnableTaskWindows(WindowList);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; Result := &nbsp;ItemIDList &lt;&gt; nil;<br>&nbsp; &nbsp; &nbsp; if Result then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ShGetPathFromIDList(ItemIDList, Buffer);<br>&nbsp; &nbsp; &nbsp; &nbsp; ShellMalloc.Free(ItemIDList);<br>&nbsp; &nbsp; &nbsp; &nbsp; Directory := Buffer;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; ShellMalloc.Free(Buffer);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br>是这么申明的
 
procedure TForm_Document_Info.Button1Click(Sender: TObject);<br>var<br>&nbsp; Dir: string;<br>begin<br>&nbsp; Dir := '';<br>&nbsp; if SelectDirectory('kkkk','C:/',Dir) then<br>&nbsp; &nbsp; Label1.Caption := Dir;<br><br>end;<br>我试了一下,看看这个就知道了
 
selectdirectory(标题,显示时选定的路径('c:/windows'),预先定义的一个变量作返回选定的路径);<br>例如:<br>procedure test;<br>var dir:String;<br>begin<br>selectdirectory('我选择的方向','c:/windows',dir);<br>//如果你选了路径,则dir返回你选择的路径.<br>end;
 
Delphi的FileCtrl单元定义了两个调用SelectDirectory函数的方法,函数原型为:<br>function SelectDirectory(var Directory: string;<br>&nbsp; Options: TSelectDirOpts; HelpCtx: Longint): Boolean; overload;<br>function SelectDirectory(const Caption: string; const Root: WideString;<br>&nbsp; out Directory: string): Boolean; overload;<br><br>其中:<br>function SelectDirectory(var Directory: string;<br>&nbsp; Options: TSelectDirOpts; HelpCtx: Longint): Boolean; overload;<br>是Delphi自己实现的浏览选择目录的函数, Directory 参数返回你所选择的目录;<br><br>function SelectDirectory(const Caption: string; const Root: WideString;<br>&nbsp; out Directory: string): Boolean; overload;<br>是Delphi对Windows的API函数的封装,const Caption: string中的const<br>是Delphi参数传递的一种方式,Root是从哪个根目录开始浏览, Directory参数返回<br>你所选择的目录!<br>
 
多人接受答案了。
 
顶部