Wolfgang Chien's Homepage | Delphi學習筆記 - 問答篇 |
在 TTable.Post 之前會先檢查 Key 是否重覆, 如果重覆會當出 "Key violation",我想在當出來之前先自行判斷,以便顯示文訊息. 但我不知如何寫, 請教我好嗎?>程式如下:
try Table1.Post; except if (索引值重覆) then begin 顯示錯誤訊息... ............... ............... end; end;
有三個方案可以解決您的問題
宅 borland 洽詢中文應用組件
修改 res 資源檔
甲. 如果您有 VCL 原始程式, 那 --
![]() |
0) 備份以下程序提到任何檔案 |
![]() |
1) 用文書編輯器編輯 \delphi\vcl\dbconsts.rc, 將其中的英文訊息改成中文 |
![]() |
2) 以 brc.exe 等工具程式將上述 rc 轉譯成 dbconsts.res |
![]() |
3) 將 dbconsts.res 複製到 delphi\lib 目錄 |
![]() |
4) 啟動 Delphi, 主選單 Options | Rebuild Library |
乙. 如果您是用 Delphi 2.0, 那恭喜恭喜, 直接到 Delphi 2.0 深度歷險 --
http://www.aaa.hinet.net/delphi , 在'全部的免費元件及工具'中有
CPATCH.ZIP 簡單的Delphi 2.0 中文修正套件,作者:李匡正、錢達智及李維,將其 .DCU、.RES 複製到\Lib 目錄下後進入Delphi 整合開發環境 Rebuild Library 即可。
去 try...except 攔工錯誤狀況.
小弟手邊的參考資料如下:
![]() |
1. Delphi 2.0 光碟片中 \Info\Borland\TechInfo\TechInfo.HLP, 找技術文件編號 2814: Handling EDBEngineError Exceptions |
![]() |
2. 在 Doc 目錄有一個 DbiErrs.int, 您可以從中查到各個 ErrCode 的常數定義 |
![]() |
3. 到 Borland 的網頁: http://www.borland.com/TechInfo/bde/bde.html
BDE Tech Support Page, 取回:
<後記> Borland 的 WWW 重新整理過了, 請改改到以下的位址 -- http://www.borland.com/techsupport/bde/delphifiles.html (相當不錯的方案) (DbeError.zip) Database error handling example. This example displays all information from an EDBEngineError or EDatabaseError exception. The example be easily integrated into existing database programs by using the dbengine unit included. Also displays native errors from SQL Servers. |
如沾舉例的話: (paradox file)
implementation {$R *.DFM} uses DbiErrs; procedure TForm1.Button1Click(Sender: TObject); var i: integer; bViolation: boolean; begin try Table1.Post; except On E: EDBEngineError do begin bViolation := False; for i := 0 to E.ErrorCount - 1 do begin if E.Errors[i].ErrorCode = DBIERR_KEYVIOL then begin ShowMessage('鍵值重覆'); bViolation := True; end; end; if not bViolation then raise EDatabaseError.Create(E.Message); end; end; end;
首頁 | 學習筆記 | 主題公園 | 軟體下載 | 關於本站 | 討論信群 | 相約下次 |