TCustomRVReportGenerator.OnError

<< Click to display table of contents >>

TCustomRVReportGenerator.OnError

Occurs if an error happens while generating a report.

type

  TRVReportGeneratorError = (

    // rules

    rvrgeRuleInvalidRange, rvrgeRuleOverlaps,

    // queries

    rvrgeNoQueryProcessor, rvrgeQueryExecution, 

    rvrgeRecordCountIsRequired,

    // variables

    rvrgeVariableUnknown, rvrgeVariableInvalidValue,

    rvrgeVariableInvalidName, rvrgeVariableUnsupportedObject,

    // data fields

    rvrgeFieldUnknown, rvrgeFieldInvalidValue, 

    rvrgeFieldUnsupportedType, rvrgeFieldUnknownType,

    rvrgeFieldUnknownRule,

    // fields

    rvrgeInvalidTypeCast, rvrgeInvalidFormatString,

    rvrgeCustomFieldTypeError,

    // commands

    rvrgeCommandUnknown, rvrgeCommandNeedsParam,

    rvrgeCommandDoesNotNeedParam, rvrgeCommandWrongParamValue,

    rvrgeCommandSyntaxError, rvrgeCommandUnmatched,

    rvrgeCommandMustBeInQuery, rvrgeCommandWrongContext,

    // cross-tab

    rvrgeCrossTabInvalid, rvrgeCrossTabInvalidPosition,

    rvrgeCrossTabNoRules,

    rvrgeCrossTabUnknownField,

    rvrgeCrossTabWrongContext, rvrgeCrossTabRecordDoesNotMatch,

    rvrgeCrossTabDuplicateRecords,

    rvrgeCrossTabKeyFieldInCrossTabColumn,

    rvrgeCrossTabNoCrossTabColumns, rvrgeCrossTabTooManyColumns,

    rvrgeCrossTabTooManyTotalColumns,

    // functions

    rvrgeFuncParenthesisExpected, rvrgeFuncUnknown,

    rvrgeFuncBadParam, rvrgeFuncMustBeInCrossTabSummary,

    rvrgeFuncCannotBeCalculated,

    // expressions

    rvrExpressionParserError, rvrExpressionEvaluationError,

    // others

    rvrgeInternalError

    );

 

  TRVReportGeneratorErrorEvent = procedure (

    Sender: TCustomRVReportGenerator;

    ErrorCode: TRVReportGeneratorError; 

    const RelatedText: TRVUnicodeString;

    RelatedObject: TObject; var Proceed: Boolean) of object;

 

property OnError: TRVReportGeneratorErrorEvent;

This event can be processed:

to display an error message,

to abort a report generation on some (or all) errors.

By default, this event is called in the context of the main process (even if reports are generated in a background thread), to allow interacting with user interface controls. If you want to call it in a thread context, exclude rvrgeOnError from SynchronizedEvents.

Parameters

ErrorCode – a code identifying the error.

RelatedText, RelatedObject provide additional information about this error.

You can assign False to Proceed to abort the report generation. In this case, this error is treated as critical, and Execute will return False.

Errors while checking table row generation rules for correctness

For this kind of errors, RelatedObject is TRVRowGenerationCustomRule.

Error

Meaning

RelatedText

rvrgeRuleInvalidRange

The rule has an incorrect range of rows (too small or too large row indexes, or these rows overlap other rows because their cells are merged vertically).

Empty

rvrgeRuleOverlaps

The rule has a range of rows intersecting with one of the previous rules in the same table

Empty

Errors while executing a data query (such as SQL SELECT statement)

For this kind of errors, RelatedObject is either TRVRowGenerationCustomRule or TRVReportTableCellData.

Error

Meaning

RelatedText

rvrgeNoQueryProcessor

The report generator was not able to create a query processor for this data query.

Data query string

rvrgeQueryExecution

An error occurred while executing a data query

Data query string

rvrgeRecordCountIsRequired

This type of report requires a known record count before retrieving data, but the query processor cannot provide it. In the current version, a record count is needed: for column copying in row generation rules, for cross-tab reports

Empty

Errors while processing variables

For this kind of errors, RelatedObject is TRVReportGenerationSession.

Error

Meaning

RelatedText

rvrgeVariableUnknown

A field refers to a non-existent variable

Variable name

rvrgeVariableInvalidValue

An improper value of a variable. For example, a variable in "If" command cannot be evaluated as True or False.

Field code

rvrgeVariableInvalidName

An incorrect (for example, empty) variable name

Variable name

rvrgeVariableUnsupportedObject

A field needs insertion of an object associated with a variable, and this object has a class unsupported by the report generator

Variable name

Errors while processing data fields

For this kind of errors, RelatedObject is TRVReportGenerationSession.

Error

Meaning

RelatedText

rvrgeFieldUnknown

A field refers to a non-existent data field

Data field name

rvrgeFieldInvalidValue

An improper value of a a data field. For example, a data field in "If" command cannot be evaluated as True or False, or a format of content of a Blob field cannot be detected

Field code or data field name

rvrgeFieldUnsupportedType

A data field has an unsupported type

Data field name

rvrgeFieldUnknownRule

A field refers to a non-existent row generation rule

Rule name

Common errors while processing data fields, cross-tab header fields, functions

For this kind of errors, RelatedObject is TRVReportGenerationSession.

Error

Meaning

RelatedText

rvrgeFieldUnknownType

Unknown value in <field type>

Field code

rvrgeInvalidTypeCast

The value cannot be converted to <field type>

Field code

rvrgeInvalidFormatString

Error in <format string>

Field code

rvrgeCustomFieldTypeError

An error was reported by a custom field type handler. The reason may be because the field data are inappropriate, or a format string is erroneous.

Field code

Errors while processing commands

For this kind of errors, RelatedObject is TRVReportGenerationSession.

Error

Meaning

RelatedText

rvrgeCommandUnknown

Unknown command

Field code

rvrgeCommandNeedsParam

This command requires parameter(s)

Field code

rvrgeCommandDoesNotNeedParam

This command requires no parameters

Field code

rvrgeCommandWrongParamValue

A parameter value for this command is incorrect

Field code

rvrgeCommandSyntaxError

A syntax error in the command code

Field code

rvrgeCommandUnmatched

Unmatched commands (for example, "If" without "EndIf")

Field code

rvrgeCommandMustBeInQuery

This command must be inserted in a text affected by a data query

Field code

rvrgeCommandWrongContext

This command is not valid in this place of document (for example, "ListReset" command must be in a numbered paragraph)

Field code

Errors while making a cross-tab report

Error

Meaning

RelatedText

RelatedObject

rvrgeCrossTabInvalid

Table.CrossTabulation is incorrect.

Possible reasons:

empty Table.CrossTabulation.Levels[].FieldName;

empty Table.CrossTabulation.Levels[].DataQuery, if they are required for the given ColumnGenerationType;

invalid values (or a combination of values) for MinValue, MaxValue, Step, if ColumnGenerationType = rvcgtRange

Empty

TRVReportTableItemInfo

rvrgeCrossTabInvalidPosition

Position or structure of a cross-tab header is incorrect.

Empty

TRVReportTableItemInfo

rvrgeCrossTabNoRules

A cross tabulation is defined for a table, but this table has no row generation rules, or the first rule is invalid

Empty

TRVReportTableItemInfo

rvrgeCrossTabUnknownField

Table.CrossTabulation.Levels[].FieldName or CaptionFieldName does not exists in the results of the respective data query (if ColumnGenerationType <> rvcgtRange)

Field name

TRVCrossTabLevel

A cross-tab header field refers to a non-existent data field

Field name

TRVReportGenerationSession

rvrgeCrossTabWrongContext

A cross-tab header field is found outside a cross-tab header cells

Field code

TRVReportGenerationSession

rvrgeCrossTabRecordDoesNotMatch

A record in the result of a row generation rule's DataQuery contains a combination of values of column fields not corresponding to any cross-tab data column

Empty

TRVReportGenerationSession

rvrgeCrossTabDuplicateRecords

A record in the result of a row generation rule's DataQuery contains the same combination of values of key fields and column fields as one of previous records.

Empty

TRVReportGenerationSession

rvrgeCrossTabKeyFieldInCrossTabColumn

One ore more key fields is included in column fields

Field name

TRVRowGenerationRule

rvrgeCrossTabNoCrossTabColumns

A cross tabulation contains 0 data columns

Empty

TRVReportTableItemInfo or TRVCrossTabLevel, depending on ColumnGenerationType

rvrgeCrossTabTooManyColumns

A group of columns in a cross-tab level exceeds level.MaxColCount. In this case, only the first MaxColCount columns are used.

Empty

TRVCrossTabLevel

rvrgeCrossTabTooManyTotalColumns

A total number of column repetitions exceeds MaxColCount

Empty

TRVReportTableItemInfo

Errors while processing functions

For this kind of errors, RelatedObject is TRVReportGenerationSession.

Error

Meaning

RelatedText

rvrgeFuncParenthesisExpected

An opening or closing bracket around the function parameter is missing

Field code

rvrgeFuncUnknown

Unknown function name

Field code

rvrgeFuncBadParam

A function parameter is not a valid value field name

Field code

rvrgeFuncMustBeInCrossTabSummary

A function field is inserted not in a proper place

Field code

Errors while processing expressions

For this kind of errors, RelatedObject is TRVExpressionCalculator.

Error

Meaning

RelatedText

rvrExpressionParserError

An error occurs when parsing the expression

Expression text

rvrExpressionEvaluationError

An error occurs when evaluating the expression

Expression text

RelatedObject (TRVExpressionCalculator) allows receiving additional information about the reason of this error and the position in expression where it happened.

Other errors

Error

Meaning

RelatedText

RelatedObject

rvrgeInternalError

An exception occurred while generating a report

Exception message

Exception

 

Example 1

How to process error messages in OnError event.

Before using RVReportGetErrorString, call RWA_LocalizeErrorMessages.

procedure TForm1.RVReportGenerator1Error(

  Sender: TCustomRVReportGenerator;
  ErrorCode: TRVReportGeneratorError; 

  const RelatedText: TRVUnicodeString;
  RelatedObject: TObject; var Proceed: Boolean);
var
  Msg1, Msg2: TRVUnicodeString;
const
  MaxErrorCount = 1000;
begin
  if lstMessages.Items.Count = MaxErrorCount then
    lstMessages.Items.Add(RWA_GetS(rwm_log_TooManyErrors));
  if lstMessages.Items.Count > MaxErrorCount then
    exit;
  RVReportGetErrorString(ErrorCode, Msg1, Msg2, RelatedObject);
  if Msg1 <> '' then
    Msg2 := Msg1 + ': ' + Msg2;
  Msg2 := Format(String(Msg2), [RelatedText]);
  lstMessages.Items.Add(String(Msg2));
end;

 

Example 2

This example shows how to use custom error messages. This example is simplified, it does not provide detailed information about errors in expressions.

const ErrorMsg: array[TRVReportGeneratorError] of String =
 (

   'Rule error: invalid row or column range',

   'Rule error: overlapping rows',

   'Query error: can''t create query processor for %s',

   'Query error: execution error for %s',

   'Query error: this type of report requires a known record count before retrieving records',

   'Variable error: unknown variable %s',

   'Variable error: invalid value for %s',

   'Variable error: invalid name %s',

   'Variable error: unsupported object in %s',

   'Data field error: unknown field %s',

   'Data field error: invalid value for %s',

   'Data field error: unsupported field type for %s',

   'Data field error: invalid type in %s',

   'Data field error: unknown row generation rule in the field %s',

   'Field error: invalid type casting in %s',

   'Field error: invalid format string %s',

   'Field error: invalid data or format string for a custom field type',

   'Command error: unknown command %s',

   'Command error: parameters are required in %s',

   'Command error: this command must not have parameters: %s',

   'Command error: wrong parameter value: %s',

   'Command error: syntax error %s',

   'Command error: unmatched command %s',

   'Command error: a command must be in content affected by a query: %s',

   'Command error: the command is not valid in its context: %s',

   'Cross-tab error: invalid cross-tab definition',

   'Cross-tab error: invalid cross-tab header location',

   'Cross-tab error: at least one row generation rule is required',

   'Cross-tab error: unknown field %s',

   'Cross-tab error: cross-tab field must be in a cross-tab header',

   'Cross-tab error: a record does not match the cross-tab columns (will be skipped)',

   'Cross-tab error: two or more records match the same cross-tab cell (all but the first one will be skipped)',

   'Cross-tab error: the same field is used both as a key field as a cross-tab header field: %s',

   'Cross-tab error: no columns',

   'Cross-tab error: too many columns in a group',

   'Cross-tab error: too many total columns',

   'Function error: parenthesis is expected in %s',

   'Function error: unknown function %s',

   'Function error: bad parameters in %s',

   'Function error: function must be in a cross-tab summary rows or columns',

   'Function error: function cannot be calculated',

   'Expression parsing error in %s', 

   'Expression evaluation error: %s',

   'Internal error'

    );
 
procedure TForm1.RVReportGenerator1Error(

  Sender: TCustomRVReportGenerator;
  ErrorCode: TRVReportGeneratorError; 

  const RelatedText: TRVUnicodeString;
  RelatedObject: TObject; var Proceed: Boolean);
var S: TRVUnicodeString;
begin
  S := Format(ErrorMsg[ErrorCode], [RelatedText]);
  Memo1.Lines.Add(S);
end;