Compile Method

Applies to TestComplete 15.70, last modified on December 17, 2024

Description

The regular expressions are stored by the engine, not in literal form, but in special internal representation. This significantly accelerates the matching operations. Upon changing the Expression property it is automatically converted when you call Exec, ExecNext, ExecPos, Substitute methods.

Use the RegExpr.Compile method for the enforced expression conversion.

If compilation failed you can get the error code via the LastError property and position in the regular expression where the error occurred via the CompilerErrorPos property.

Declaration

RegExprObj.Compile()

RegExprObj An expression, variable or parameter that specifies a reference to a RegExpr object
Result None

Applies To

The method is applied to the following object:

Result Value

None.

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

Using Regular Expressions in Scripts
Using Regular Expressions in Scripts
Expression Property
RegExpr.LastError
RegExpr.CompilerErrorPos

Highlight search results