線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:776
推到 Plurk!
推到 Facebook!

TADOQuery的OnWillChangeRecord事件無法攔截例外

尚未結案
inwuinfo
一般會員


發表:4
回覆:0
積分:0
註冊:2004-05-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-05-21 00:45:19 IP:61.230.xxx.xxx 未訂閱
請問大家: 我在TADOQuery的OnWillChangeRecord事件撰寫程式碼, 但若發生錯誤的時候, 並無法產生錯誤訊息, 而是被吃掉了, 怎麼會這樣? procedure TfmORDERS.ADOQueryWillChangeRecord(DataSet: TCustomADODataSet; const Reason: TEventReason; const RecordCount: Integer; var EventStatus: TEventStatus); begin if Reason = erUpdate then begin try ADOQuery1.SQL.Text := 'UPDATE Product SET ' 'Quanity = Quanity :UpdateQuanity ' 'WHERE ProductID = :ProductID '; ADOQuery1.Parameters.ParamByName('UpdateQuanity').Value := DataSet.FieldByName('Quantity').NewValue; ADOQuery1.Parameters.ParamByName('ProductID').Value := DataSet.FieldByName('ProductID').NewValue; ADOQuery1.ExecSQL; except ShowMessage('有錯誤!'); raise; end; end; end; 在程式中的SQL若執行有問題, 就停在ExceSQL這一行, 並不會跑到Except那一段? 謝謝!
Chance36
版主


發表:31
回覆:1033
積分:792
註冊:2002-12-31

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-06-04 19:08:03 IP:211.20.xxx.xxx 未訂閱
inwuinfo 你好     OnWillChangeRecord事件中有個參數var EventStatus: TEventStatus就是給你通知AdoQuery在此事件中發生了什麼事的參數,試著改成如下程式架構
procedure TfmORDERS.ADOQueryWillChangeRecord(DataSet: TCustomADODataSet;
     const Reason: TEventReason; const RecordCount: Integer;
     var EventStatus: TEventStatus);
begin
  if Reason = erUpdate then Begin
    try
      ........
      EventStatus := esOK ; // 正常處理完成
    except
      raise; 
      EventStatus := esErrorsOccured ; // 有錯誤發生
      // TEventStatus = (esOK, esErrorsOccured, esCantDeny, esCancel, esUnwantedEvent); 
      // 依實際狀況選用一個
    end;
  end;
end;
系統時間:2024-07-04 12:04:58
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!