2011-02-07 10 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:\データ\ 2011 \ ORDLY.MDX

+1

関数が失敗した場合、戻り値はゼロです。拡張エラー情報を取得するには、GetLastErrorを呼び出します。 –

+0

この関数は機能しました。ファイルがコピーされました。デルファイだけが名前を変更したファイルを気に入らなかった。私がdBASEでそれらを開いたとき、彼らは大丈夫でした。 – ChuckO

答えて

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|=======================|