Compile Method

Applies to TestComplete 15.64, last modified on June 12, 2024


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.



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



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


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

    // Specifies a regular expression
    MyRegExp.Expression := '[]';
    // Forces expression conversion
    // Performs operations over text
    // 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) + ')');

See Also

Using Regular Expressions in Scripts
Using Regular Expressions in Scripts
Expression Property

Highlight search results