Wolfgang Chien's Homepage | Delphi學習筆記 - 問答篇 |
在 Delphi 中要如何救回假性刪除的資料呢? 就如 DBASE 的 Recall 指令一般的功能.
處理步驟
![]() |
1. 首先, 要先呼叫 BDE API DbiSetProp() 將 Softdelete 設為 ON |
![]() |
2. 呼叫 DbiUndeleteRecord() 進行 recall 的動作 |
注意事項
![]() |
將 Softdelete 設為 ON 後, Table 要 refresh 一次, 以便 Data-aware元件(例如 DbGrid)顯示已刪除的資料 |
![]() |
呼叫 DbiUndeleteRecord() 之前, 切記要呼叫 Table 的 UpdateCursorPos, 讓 BDE 中的記錄位置與 Dataware 元件位置取得一致. |
![]() |
Table 的 TableType 保險起見請設為 ttDBASE |
![]() |
軟體內附的 BDE API Help 的 Online help 中, 有關 DbiSetProp() 的 Delphi 範例錯了一列, 正確的請見本信附上的程式. |
參考資料
附上測試用的程式如下:
... implementation ... procedure fDbiSetProp1(Table: TTable; SoftDelete: Boolean); var rslt: DBIResult; Props: CURProps; begin Check(DbiGetCursorProps(Table.Handle, Props)); if Props.szTableType <> szDBASE then raise EDBEngineError.Create(DBIERR_NOTSUPPORTED); // Make sure that the property can be set rslt := DbiValidateProp(hDBIObj(Table.Handle), curSOFTDELETEON, True); if rslt = DBIERR_NONE then // Set the property Check(DbiSetProp(hDBIObj(Table.Handle), curSOFTDELETEON, Longint(SoftDelete))) else raise EDBEngineError.Create(rslt); end; procedure fDbiUndeleteRecord(dBASETbl: TTable); var CProps: CurProps; begin Check(DbiGetCursorProps(dBASETbl.Handle, CProps)); // Raise an EDBEngineError exception if the table is not dBASE if StrIComp(CProps.szTableType, szDBASE) <> 0 then raise EDBEngineError.Create(DBIERR_NOTSUPPORTED); // Raise an EDatabaseError exception if the cursor does not have soft deletes on if CProps.bDeletedOn = False then raise EDatabaseError.Create('Soft deletes is not on'); Check(DbiUndeleteRecord(dBASETbl.Handle)); end; procedure TForm1.Button1Click(Sender: TObject); begin fDbiSetProp1(Table1, CheckBox1.Checked); Table1.Refresh; // 這列要加上去 end; procedure TForm1.Button2Click(Sender: TObject); begin Table1.UpdateCursorPos; // 這列可省不得的... fDbiUndeleteRecord(Table1); end; ...
首頁 | 學習筆記 | 主題公園 | 軟體下載 | 關於本站 | 討論信群 | 相約下次 |