Applies to TestComplete 14.30, last modified on November 21, 2019

Description

Use the RegExpr.CompilerErrorPos property to find the position where the compilation stopped. If the error occurred verify the syntax of the regular expression.

Declaration

RegExprObj.CompilerErrorPos

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 integer value specifying the error position.

This property returns 0 if the 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
LastError Property

Highlight search results