2011-02-07 38 views
0

我用下面的代碼DBF/MDX文件從一個文件夾複製到另一個:錯誤複製DBF/MDX文件

procedure TfrmMain.MyCopyFile(S1, S2: string); 
begin 
    if not FileExists(S2) then 
     CopyFile(PCHAR(S1), PCHAR(S2), true) 
    else 
     if Application.MessageBox(PCHAR('Overwrite existing file ' + S2 + '?'), 'File exists in folder',MB_YESNO + MB_DEFBUTTON1) = IDYES 
      then CopyFile(PCHAR(S1), PCHAR(S2), false) 
end; 

的代碼工作正常時,表名保持不變。

如果我更改了表的名稱:

MyCopyFile(CurPath + '\orders.dbf', NewPath + '\ordly.dbf'); 
    MyCopyFile(CurPath + '\orders.mdx', NewPath + '\ordly.mdx'); 

當我嘗試打開ordly.dbf我得到一個錯誤信息:

損壞的表/索引標題。
文件:C:\ DATA \ 2011 \ ORDLY.MDX

+1

如果函數調用失敗,返回值是零。要獲得擴展的錯誤信息,請調用GetLastError。 – 2011-02-07 23:19:02

回答

7

的問題是由於相關聯的數據文件(表名)的名稱內的mdx格式存儲。因爲當你重命名mdx文件時,索引仍然指向舊的數據文件的名稱。

檢查此鏈接以查看mdx文件的結構。

The Structure of Multiple Index files (*.mdx)

0 | Version number  *1|^
    |-----------------------| | 
1 | Date of creation  | | 
2 |  YYMMDD   | | 
3 |      | | 
    |-----------------------| | 
4 | Data file name  | File 
5 | (no extension)  | Header 
    :      : | 
    :      : | 
19 |      | | 
    |-----------------------| | 
20 | Block size   | | 
    |      | | 
    |-----------------------| | 
22 | Block size adder N | | 
    |      | | 
    |-----------------------| | 
24 | Production index flag | | 
    |-----------------------| | 
25 | No. of entries in tag | | *2 
    |-----------------------| | 
26 | Length of tag   | | *3 
    |-----------------------| | 
27 | (Reserved)   | | 
    |-----------------------| | 
28 | No.of tags in use  | | 
    |      | | 
    |-----------------------| | 
30 | (Reserved)   | | 
    |      | | 
    |-----------------------| | 
32 | No.of pages in tagfile| | 
    |      | | 
    |      | | 
35 |      | | 
    |-----------------------| | 
36 | Pointer to first free | | 
    | page     | | 
    |      | | 
39 |      | | 
    |-----------------------| | 
40 | No.of block available | | 
    |      | | 
    |      | | 
43 |      | | 
    |-----------------------| | 
44 | Date of last update | | 
    |  YYMMDD   | | 
46 |      | | 
    |-----------------------| | 
47 | (Reserved)   | | 
    |-----------------------| | 
48 | (Garbage)    | | 
    :      : | 
    :      : | 
    |      | |  ___|=======================| 
543|      | _V___ /0 | Tag header page no. | 
    |-----------------------| | / |      | 
544| Tag table entries  | Tag / |      | 
    |      | Table | 3 |      | 
    :.......................: | |  |-----------------------| Tag 
    :      : | | 4 | Tag name    | table 
    :.......................: | |  :      : 
    :      : | /  :      : 
    :      : |/  |      | 
    :.......................:__|_/  14 |      | 
    :      : |   |-----------------------| 
    :      : |  15 | Key format   *4 | 
    :      : |   |-----------------------| 
    :.......................:__|_  16 | Forward tag thread (<)| 
    :      : | \   |-----------------------| 
    :      : | \  17 | Forward tag thread (>)| 
    :      : | \  |-----------------------| 
    :      : | | 18 | Backward tag thread *5| 
    |      | | |  |-----------------------| 
    |      | | | 19 | (Reserved)   | 
M*N|      |__V__ |  |-----------------------| 
    |=======================|^ | 20 | Key type   *6 | 
    0| Pointer to root page | | |  |-----------------------| 
    |      | | | 21 | (Reserved)   | 
    |      | | |  :      : 
    3|      | | |  :      : 
    |-----------------------| | | 31 |      | 
    4| File size in pages | Tag |  |-----------------------| 
    |      | header| 32 | (Garbage)    | 
    |      | | |  :      : 
    7|      | | |  |      | 
    |-----------------------| |  \ N |      | 
    8| Key format   *7 | |  \____|=======================| 
    |-----------------------| | 
    9| Key type   *8 | | 
    |-----------------------| | 
10| (Reserved)   | | 
    |      | | 
    |-----------------------| | 
12| Index key length *9 | | 
    |      | | 
    |-----------------------| | 
14| Max.no.of keys/page | | 
    |      | | 
    |-----------------------| | 
16| Secondary key type *10| | 
    |      | | 
    |-----------------------| | 
18| Index key item length | | 
    |      | | 
    |-----------------------| | 
20| (Reserved)   | | 
    |      | | 
    |      | | 
    |-----------------------| | 
23| Unique flag   | | 
    |-----------------------| | 
    |      | | 
    :      : | 
    :      :__V__ 
N*M|=======================|