全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1015
推到 Plurk!
推到 Facebook!

不知錯誤在哪裡,可否請各位前輩看看

答題得分者是:P.D.
kevinsoung
一般會員


發表:36
回覆:41
積分:15
註冊:2011-11-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2016-09-15 10:41:42 IP:1.161.xxx.xxx 訂閱
各位前輩
因需要所以在網路上 找到下面的Code,將該Code放入我的 Delphi7 內 然後 Compile
就會出現錯誤
Build
[Error] Unit1.pas(37): Missing operator or semicolon
[Error] Unit1.pas(40): Missing operator or semicolon
[Error] Unit1.pas(41): Missing operator or semicolon
[Error] Unit1.pas(44): Undeclared identifier: 'CopyDir'
[Warning] Unit1.pas(47): Unsafe type 'PChar'
[Warning] Unit1.pas(47): Unsafe type 'PChar'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'

可否請各位前輩幫我看看是錯在哪裡 萬般感激
(附件為錯誤的畫面)

[code delphi]
//----------------------------------------------------------------------------    
uses SysUtils;    //【函式作用】複製整個目錄至指定路徑內。
//【輸入引數】
//  vSrcPath        來源目錄路徑。
//  vDestPath       目的目錄路徑。
//  [vOverwrite]    選擇性引數,遇到相同檔名檔案存在時是否要覆寫,{true→覆寫|false→不覆寫}。@=true。
//【函式傳回】Boolean,{true→執行成功|false→執行失敗}。
//【作者版本】Dalman, 2002/10/09, 1.0.0。    
function _CopyDir(const vSrcPath, vDestPath: AnsiString; vOverwrite: Boolean=true): Boolean;
var
  r: TSearchRec;
  s, d: AnsiString;
  ns, nd: AnsiString;
begin
  try
    try
      result := false;
      s := IncludeTrailingPathDelimiter(vSrcPath);
      d := IncludeTrailingPathDelimiter(vDestPath);
      if not ForceDirectories(d) then Exit;                                   //若目的目錄無法建立時,則...
      //---- 開始遞回搜尋複製目錄及檔案群 ------------------------------------
      if FindFirst(s   '*.*', faAnyFile, r) = 0 then begin
        repeat
          if (r.Name <> '.') and (r.Name <> '..') then begin
            ns := s   r.Name;                                                 //新來源目錄路徑或檔案名稱。
            nd := d   r.Name;                                                 //新目的目錄路徑或檔案名稱。
            if (r.Attr and faDirectory) = faDirectory then begin              //若為目錄時,則...
              if not ForceDirectories(nd) then Exit;                          //嚐試建立目的目錄。
              CopyDir(ns, nd);                                                //再找下一層子目錄複製。
            end else begin
              if FileExists(nd) and (not vOverwrite) then Continue;           //若目的檔案存在且又不覆寫時,則...
              if not CopyFile(PChar(ns), PChar(nd), false) then Exit;
            end;
          end;
        until FindNext(r) <> 0;
        result := true;
      end;
    except
      on e: Exception do result := false;
    end;
  finally
    FindClose(r);
  end;
end;
//----------------------------------------------------------------------------
[/code]
附加檔案:57da0a668a10b_Error_1.jpg
P.D.
版主


發表:603
回覆:4038
積分:3874
註冊:2006-10-31

發送簡訊給我
#2 引用回覆 回覆 發表時間:2016-09-16 00:55:13 IP:118.169.xxx.xxx 未訂閱
要幫你查問題在那, 有實際困難, 最簡單的方式, 就是在誤提示雙擊兩下, delhpi會跳到錯誤點, 可查看該點的問題,
但我看前三個的錯誤通常是程式的 begin..end 不對稱所造成,
我看所po的程式,
ns := s r.Name; --> 這個除非是貼文有問題, 否則delphi不允許這種語法, 也就是 s 後面空白被視為程式段未完成

第4個錯誤, 我不知道 copydir 是否為delphi內建的函式, 如果是的話, 必須找出 copydir 存在的 pas 並予以 uses 進來, 如果不是, 則請你找原來的出處, 是否 copydir 有另外的 pas 或 dll 要含括進來

至於 warnning 只是警告, 不影響編譯!
kevinsoung
一般會員


發表:36
回覆:41
積分:15
註冊:2011-11-09

發送簡訊給我
#3 引用回覆 回覆 發表時間:2016-09-16 09:50:46 IP:122.100.xxx.xxx 訂閱
感謝版主的回覆
我會再試試看
系統時間:2024-04-26 9:27:36
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!