Delphi Examples: DbiGetErrorInfo

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Delphi Examples: DbiGetErrorInfo

Return to chapter overview

Get descriptive error information about the last error

In addition the the most recent error, this function displays error contexts for up to four error messages on the error stack. This example uses the following input:

 fDbiGetErrorInfo(DbiOpenLDList(hCur), ErrorList);

 

The procedure is defined as:

procedure fDbiGetErrorInfo(ErrorCode: DbiResult; ErrorList: TStringList);

var

 ErrorInfo: DBIErrInfo;

 ErrorString: String;

begin

if (ErrorCode <> dbiERR_NONE) then begin

   ErrorList.Clear;

   Check(DbiGetErrorInfo(True,ErrorInfo));

  if (ErrorCode = ErrorInfo.iError) then begin

     ErrorList.Add('Error Number: ' + IntToStr(ErrorInfo.iError));

     ErrorList.Add('Error Code: ' + StrPas(ErrorInfo.szErrcode));

    if (StrLen(ErrorInfo.szContext[1]) <> 0) then

       ErrorList.Add('Error Context1: ' + StrPas(ErrorInfo.szContext[1]));

    if (StrLen(ErrorInfo.szContext[2]) <> 0) then

       ErrorList.Add('Error Context2: ' + StrPas(ErrorInfo.szContext[2]));

    if (StrLen(ErrorInfo.szContext[3]) <> 0) then

       ErrorList.Add('Error Context3: ' + StrPas(ErrorInfo.szContext[3]));

    if (StrLen(ErrorInfo.szContext[4]) <> 0) then

       ErrorList.Add('Error Context4: ' + StrPas(ErrorInfo.szContext[4]));

  end

  else begin

     SetLength(ErrorString, dbiMaxMsgLen + 1);

     Check(DbiGetErrorString(ErrorCode, PChar(ErrorString)));

     SetLength(ErrorString, StrLen(PChar(ErrorString)));

     ErrorList.Add(ErrorString);

  end;

end;

end;