void ReportError(short printJob)
{
Crystal Report Engine error processing can be most efficiently handled by a separate internal function, such as the one shown here, that is called during a print job. The Event code that is evaluated above calls the ReportError function whenever a Crystal REAPI function returns an error. The code for the ReportError function appears here as an example of how to access and evaluate Crystal Report Engine errors. The error number returned by PEGetErrorCode can be used to control how your application reacts to different types of Crystal Report Engine errors.
Note: The REAPI functions described here, PEGetErrorCode and PEGetErrorText, are specific to REAPI error handling. For complete descriptions of these functions, see Crystal Report Engine Index, or search for the functions by name in Crystal Reports Developer's Help (CrystalDevHelp.chm). The function PEGetHandleString is used to retrieve variable length strings generated by different REAPI functions.
short errorCode;
HANDLE textHandle;
short textLength;
char *errorText;
Completely processing any Crystal Report Engine error requires at least four variables like those above. While only errorCode will be needed to retrieve the Crystal Report Engine error number, the other three variables will all be needed to retrieve the actual error text.
errorCode = PEGetErrorCode(printJob);
PEGetErrorCode returns a number associated with the error that has occurred. For a list of these error codes and their meanings, see Error Codes.
PEGetErrorText ( printJob,
&textHandle,
&textLength);
errorText = (char*)malloc(textLength);
PEGetHandleString(textHandle,
errorText,
textLength);
The error text must be returned in the form of a handle to a variable length string. The handle is used, along with the PEGetHandleString function to obtain the actual error text and store it in a character array. This is a complicated process, and it should be examined carefully if your code is to work.
MessageBox( hWnd, errorText,
"Print Job Failed",
MB_OK | MB_ICONEXCLAMATION);
Once the error has been obtained, you can display error information to the user. This example simply opens a warning message box to alert the user of the problem. Using the error code and the error text, however, you can control Crystal Report Engine error messages any way that you find appropriate for your application.
return;
}
Once error processing is finished, you can return to processing the print job. If an error has occurred during the print job, however, then the print job should be terminated immediately after the error is processed. Review the evaluation of the event code above for ideas on how to terminate a print job after an error.
| Seagate Software IMG Holdings, Inc. http://www.seagatesoftware.com Support services: http://support.seagatesoftware.com |