比如在更新时

解决方案 »

  1.   

    e K e y Viol = 9729;
    eRequiredFieldMissing = 9732;
    eForeignKey = 9733;
    eDetailsExist = 9734;procedure TDataModule1.Table1DeleteError(DataSet: TDataSet;
    E: EDatabaseError; var Action: TDataAction);
    b e g i n
    if (E is EDBEngineError) then
    if (E as EDBEngineError).Errors[0].Errorcode = eDetailsExist then
    b e g i n
    M e s s a g e D l g ( '请首先删除O r d e r s . D B和I t e m s . D B的相关记录' ,
    m t Warning, [mbOK], 0);
    A b o r t ;
    e n d ;
    e n d ;procedure TDataModule1.Table2PostError(DataSet: TDataSet;
    E: EDatabaseError; var Action: TDataAction);
    var Error:Integer;
    b e g i n
    if (E is EDBEngineError) then
    b e g i n
    Error := (E as EDBEngineError).Errors[0].Errorcode;
    case Error of
    e R e q u i r e d F i e l d M i s s i n g : / /空关键字
    b e g i n
    M e s s a g e D l g ( '输入CUSTNO', mtWarning, [mbOK], 0);
    A b o r t ;
    e n d ;
    e K e y Vi o l : / /关键字重复
    b e g i n
    M e s s a g e D l g ( '不能提交记录,关键字重复', mtWa r n i n g ,
    [mbOK], 0);
    A b o r t ;
    e n d ;
    e n d ;
    e n d ;
    e n d ;B D E目录下的i d a p i . h给出了所有的常量定义,下面摘录其中的一部分:
    #define ERRCODE_KEYVIOL 1 // Key violation
    #define ERRCODE_MINVALERR 2 // Min val check failed
    #define ERRCODE_MAXVALERR 3 // Max val check failed
    #define ERRCODE_REQDERR 4 // Field value required
    #define ERRCODE_FORIEGNKEYERR 5 // Master record missing
    #define ERRCODE_DETAILRECORDSEXIST 6 // Cannot MODIFY /DELETE this Master record
    #define ERRCODE_MASTERTBLLEVEL 7 // Master Table Level is incorrect
    #define ERRCODE_LOOKUPTABLEERR 8 // Field value out of lookup tbl range
    #define ERRCODE_LOOKUPTBLOPENERR 9 // Lookup Table Open failed
    #define ERRCODE_DETA I LTBLOPENERR 10// 0x0a Detail Table Open failed
    #define ERRCODE_MASTERTBLOPENERR 11// 0x0b Master Table Open failed
    #define ERRCODE_FIELDISBLANK 12 // 0x0c Field is blank
    T D B E r r o r. E r r o r C o d e实际返回的值是上面的值加E R R B A S E _ I N T E G R I T Y。E R R B A S E
    _ I N T E G R I T Y等于9 7 2 8,在同一个文件中可以找到它们的定义。
    #define ERRBASE_INTEGRITY 0x2600 // Integrity Vi o l a t i o n
    #define DBIERR_KEYVIOL (ERRBASE_INTEGRITY + ERRCODE_KEYVIOL)
    #define DBIERR_MINVALERR (ERRBASE_INTEGRITY + ERRCODE_MINVA L E R R )
    #define DBIERR_MAXVALERR (ERRBASE_INTEGRITY + ERRCODE_MAXVA L E R R )
    #define DBIERR_REQDERR (ERRBASE_INTEGRITY + ERRCODE_REQDERR)
    #define DBIERR_FORIEGNKEYERR (ERRBASE_INTEGRITY + ERRCODE_FORIEGNKEYERR)
    #define DBIERR_DETA I L R E C O R D S E X I S T (ERRBASE_INTEGRITY + ERRCODE_DETA I L R E C O R D S E X I S T )
    #define DBIERR_MASTERTBLLEVEL (ERRBASE_INTEGRITY + ERRCODE_MASTERT B L L E V E L )
    #define DBIERR_LOOKUPTABLEERR (ERRBASE_INTEGRITY + ERRCODE_LOOKUPTA B L E E R R )
    #define DBIERR_LOOKUPTBLOPENERR (ERRBASE_INTEGRITY + ERRCODE_LOOKUPTBLOPENERR)
    #define DBIERR_DETA I LTBLOPENERR (ERRBASE_INTEGRITY + ERRCODE_DETA I LT B L O P E N E R R )
    #define DBIERR_MASTERT B L O P E N E R R (ERRBASE_INTEGRITY + ERRCODE_MASTERT B L O P E N E R R )
    #define DBIERR_FIELDISBLANK (ERRBASE_INTEGRITY + ERRCODE_FIELDISBLANK)
    #define DBIERR_MASTEREXISTS (ERRBASE_INTEGRITY + ERRCODE_MASTEREXISTS)
    #define DBIERR_MASTERT B L O P E N (ERRBASE_INTEGRITY + ERRCODE_MASTERT B L O P E N )
    #define DBIERR_DETA I LTA B L E S E X I S T (ERRBASE_INTEGRITY + ERRCODE_DETA I LTA B L E S E X I S T )
    #define DBIERR_DETA I L R E C E X I S T E M P T Y (ERRBASE_INTEGRITY + ERRCODE_DETA I L R E C E X I S T E M P T Y )
    #define DBIERR_MASTERREFERENCEERR (ERRBASE_INTEGRITY + ERRCODE_MASTERREFERENCEERR)
    #define DBIERR_DETA I LT B L O P E N (ERRBASE_INTEGRITY + ERRCODE_DETA I LT B L O P E N )
    #define DBIERR_DEPENDENTSMUSTBEEMPTY (ERRBASE_INTEGRITY + ERRCODE_DEPENDENTSMUSTBEEMPTY)
    #define DBIERR_RINTREQINDEX (ERRBASE_INTEGRITY + ERRCODE_RINTREQINDEX)
    #define DBIERR_LINKEDTBLPROTECTED (ERRBASE_INTEGRITY + ERRCODE_LINKEDTBLPROTECTED)
      

  2.   

    try
    你的代码
    except
    异常捕获
    end