LastError Property

Applies to TestComplete 15.0, last modified on November 17, 2021

Description

Use the RegExpr.LastError property to get the code of the last error that occurred during the regular expression compilation. To get the error description use the ErrorMsg property. To get the position in the regular expression where the error occurred use the CompilerErrorPos property.

Declaration

RegExprObj.LastError

Read-Only Property Integer
RegExprObj An expression, variable or parameter that specifies a reference to a RegExpr object

Applies To

The property is applied to the following object:

Property Value

The error code.

This property returns 0 if regular expression compiled successfully.

Example

The following example demonstrates how to use the RegExpr.Compile method to force expression conversion and to get conversion errors that occur during compilation.

DelphiScript

procedure CompileSample;
var
  MyRegExp: OleVariant;
  Mes: string;
  Err, Pos: integer;
begin

  MyRegExp:=HISUtils.RegExpr;
  try
    // Specifies a regular expression
    MyRegExp.Expression := '[]';
    // Forces expression conversion
    MyRegExp.Compile;
    // Performs operations over text
    …
  except
    // If a compilation error occurs…
    // Obtains the code of the occurred error
    Err := MyRegExp.LastError;
    // Obtains the description of the occurred error
    Mes := MyRegExp.ErrorMsg[Err];
    // Obtains the position, in the regular expression, where the error occurred
    Pos := MyRegExp.CompilerErrorPos;
    // Posts information on the error to the test log
    Log.Error('Error: ' + aqConvert.IntToStr(Err) + ' ' + Mes + ' (pos ' + aqConvert.IntToStr(Pos) + ')');
  end;
end;

See Also

Regular Expressions Syntax
Using Regular Expressions in Scripts
Expression Property
Compile Method
ErrorMsg Property
CompilerErrorPos Property

Highlight search results