Wolfgang Chien's Homepage | Delphi學習筆記 - 問答篇 |
在我們發展出來的資料庫程式中, 若使用者誤砍了 .MDX 的索引檔或 .MDX 損壞或變 0 Bytes 時, 一到 Table.Open 就會出現 Error, 要怎樣重新 make index file ?
![]() |
1. 先找最近的備份檔案, 如果沒有, 則備份目前的損壞資料檔 (保持現場完整嘛 :p), 然後請繼續 2. 3. 的說明. |
![]() |
2. 在 dbf 的檔頭的第 28 個 byte 記錄了這個 dbf 是否建有索引檔, 您可以將這個 byte 設為 0 |
![]() |
3. 再來, 利用 DBD 重建索引; 或者寫段程式, 以 AddIndex 加入索引也行.(作法請參照信後的程式例) |
以下有一則例子:
procedure TForm1.Button1Click(Sender: TObject); const _NoIndex: byte = 0; var fBeFixed: file of byte; begin (* 去除 DBF 檔頭的索引旗標 *) AssignFile(fBeFixed, 'C:\TEMP\CUSTOM.DBF'); FileMode := 2; Reset(fBeFixed); Seek(fBeFixed, 28); (* 將讀寫位置移至 28th *) Write(fBeFixed, _NoIndex); (* 將這個位置的內容改成零 *) CloseFile(fBeFixed); (* 要先將舊的索引檔刪掉, 否則稍候產生新的索引檔時會有困難 *) DeleteFile('C:\TEMP\CUSTOM.MDX'); (* 重新產生索引 *) with Table1 do begin AddIndex('cu_no', 'cu_no', []); AddIndex('Cu_Info', 'cu_no+cu_Name', [ixExpression]); end; (* 重建索引的說明: with Table1 do begin AddIndex('IndexTagName', 'FiledName', []); AddIndex('YourExpressIndexTagName', 'Field1+Field2', [ixExpression]); end; *) end;
首頁 | 學習筆記 | 主題公園 | 軟體下載 | 關於本站 | 討論信群 | 相約下次 |