乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Delphi獲取文件夾路徑的三種方式

       ZLM_圖書館 2014-03-03

      源:http://52wuxinle.blog.163.com/blog/static/8339236020110702019118/

      問(wèn)題一:在Win98中右擊“我的文檔”,選屬性,在彈出的“我的文檔 屬性”窗口
      中點(diǎn)擊“瀏覽”按鈕就會(huì)彈出一個(gè)“瀏覽文件夾”對(duì)話框。請(qǐng)問(wèn)這個(gè)對(duì)話框是怎么做出
      來(lái)的?
        答案:要做這個(gè)對(duì)話框有三種方法。
       ?。ㄒ唬┑谝环N方法是用Delphi提供的組件(在Win 3.1面板上)模仿在上面看到的對(duì)
      話框自己組裝一個(gè)“瀏覽文件夾”窗體。具體的做法是:
        1. 在你的Project里增加一個(gè)BorderStyle為bsDialog的新窗體;
        2.放置一個(gè)DirectoryListBox組件;
        3. 放置一個(gè)DriveComboBox組件,設(shè)置DirList為DirectoryListBox1;
        4.然后再放上兩個(gè)Button。一個(gè)“確定”(ModalResult為mrOk),一個(gè)“取消”
      (ModalResult為mrCancel);
        5.最后只要在調(diào)用這個(gè)瀏覽文件夾的地方加上一下代碼就算大功告成了:
        if Form2.ShowModal = mrOk then
        Memo1.Lines.Add(Form2.DirectoryListBox1.Directory);
       ?。ǘ┑诙N方法,在Delphi中可以通過(guò)調(diào)用SelectDirectory函數(shù)得到這種效果
        SelectDirectory在Delphi 4中的申明如下(請(qǐng)注意,一共有兩個(gè)重載的申明):
        type
        TSelectDirOpt = (sdAllowCreate, sdPerformCreate, sdPrompt);
        TSelectDirOpts = set of TSelectDirOpt;
        function SelectDirectory(var Directory: string;
        Options: TSelectDirOpts; HelpCtx: Longint): Boolean; overload;
        function SelectDirectory(const Caption: string; const Root:WideString; o
      ut Directory: string): Boolean; overload;
        第一種語(yǔ)法的Options參數(shù)指定了“瀏覽文件夾”對(duì)話框的一些選項(xiàng);參數(shù)HelpCtx
      指定上下文敏感的Help ID;Directory初始化了對(duì)話框的值,并且攜帶返回值。
        第二種語(yǔ)法的Caption參數(shù)指定對(duì)話框標(biāo)題(比如′請(qǐng)選擇XXX的文件夾′);參數(shù)
      Root指定用來(lái)瀏覽的根目錄;所選擇文件夾返回在參數(shù)Directory中。
        不管是哪種語(yǔ)法,如果在對(duì)話框中選擇了路徑并按下“確定”按鈕,SelectDirect
      ory函數(shù)返回True;在其它情況下,函數(shù)SelectDirectory就返回False。
       ?。ㄈ┑谌N方法是比較高明的解決方案。在Windows中已經(jīng)有一個(gè)專門用來(lái)處理這
      種問(wèn)題的ShellAPI函數(shù)——SHBrowseForFolder(事實(shí)上,第二種方法的第二種語(yǔ)法就是
      調(diào)用了這個(gè)API,這在Delphi的源代碼中可以得到證實(shí))。因?yàn)樗鞘褂孟到y(tǒng)已有的API
      ,這樣就不會(huì)占用太多的系統(tǒng)資源,從而減小代碼長(zhǎng)度、提高程序運(yùn)行速度,并且在Wi
      ndows的不同語(yǔ)言版本中會(huì)自動(dòng)的和Windows相適應(yīng)。具體代碼如下:
        var
        Info: TBrowseInfo;
        Dir: array[0..260] of char;
        ItemId: PItemIDList;
        begin
        with Info do
        begin
        hwndOwner := self.Handle;
        pidlRoot := nil;
        pszDisplayName := nil;
        lpszTitle := ′請(qǐng)選擇XXX的文件夾′;
        ulFlags := 0;
        lpfn := nil;
        lParam := 0;
        iImage := 0;
        end;
        ItemId := SHBrowseForFolder(Info);
        if ItemId <> nil then
        begin
        SHGetPathFromIDList(ItemId, @Dir);
        Result := string(Dir);
        end
        else
        Result := ′′;
        end;
        如果你對(duì)最后的這種方法感興趣,以Browsing for Folders為主題在Windows API
      Help中檢索將會(huì)得到更多的文檔。
        問(wèn)題二:在許多軟件的制作過(guò)程中我都遇到文件復(fù)制這個(gè)問(wèn)題,但我對(duì)文件操作很
      不熟悉。請(qǐng)問(wèn),在Delphi中有簡(jiǎn)單的方法能夠?qū)崿F(xiàn)這個(gè)功能嗎?
        答案:實(shí)現(xiàn)它的源代碼如下:
        var
        DesFile, SourFile: File;
        Buf: Byte;
        begin
        AssignFile(SrcFile, ″c:\autoexec.bat″);
        Reset(SrcFile, 1);// 1 = 逐個(gè)字節(jié)操作
        AssignFile(DesFile, ″c:\autoexec.bak″);
        Rewrite(DesFile, 1); // 同上
        while not Eof(SrcFile) do
        begin
        BlockRead(SrcFile, Buf, SizeOf(Byte)); // 從源文件中讀出來(lái)
        BlockWrite(DesFile, Buf, SizeOf(Byte)); // 寫到目標(biāo)文件中去
        end;
        CloseFile(SrcFile);
        CloseFile(DesFile);
        end;
        另外還有一個(gè)高招——直接使用API函數(shù)CopyFile。這個(gè)API的原型如下:
        BOOL CopyFile(
        LPCTSTR lpExistingFileName, // pointer to name of an existing file
        LPCTSTR lpNewFileName, // pointer to filename to copy to
        BOOL bFailIfExists // flag for operation if file exists
        );
        如:CopyFile( PChar(′c:\autoexec.bat′), PChar(′c:\autoexec.bak′), True);

       

       

      Delphi如何實(shí)現(xiàn)瀏覽文件夾,并得出所選擇的文件夾名:
      SelectDirectory函數(shù)(FileCtrl單元)
      1、function SelectDirectory(const Caption: string; const Root: WideString; out Directory: string): Boolean; overload;
      2、function SelectDirectory(var Directory: string; Options: TSelectDirOpts; HelpCtx: Longint): Boolean; overload;
      注意:使用前請(qǐng)uses FileCtrl;
      第1種調(diào)用格式示例為:
      const
        sCaption = '文件夾';       //彈出框標(biāo)題名(非彈出框窗體名)
        sRoot = '';                    //初始文件夾(如'C:\','D:\DownLoad'等, 不存在則從桌面)
      var
        sDir: string;
      begin
        if SelectDirectory(sCaption, sRoot, sDir) then
        //已返回所選文件夾路徑給sDir,自行處理
      end;
       
      第2種調(diào)用格式示例為:
      const
        SELDIRHELP = 1000;
      var
        sDir: string;            //初始文件夾(如'C:\','D:\DownLoad'等)
      begin
        sDir := '';
        if SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt], SELDIRHELP) then
          //已返回所選文件夾路徑給sDir,自行處理
      end;

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多