TROMacroParser

Overview

TROMacroParser is a class for parsing expressions that allows to replace found variables with their values.

TForm23 = class(TForm)
..
  function Now(Sender: TObject;const Parameters: array of string): string;
end;

function TForm23.Now(Sender: TObject;const Parameters: array of string): string;
begin
  Result := DateTimeToStr(SysUtils.Now);
end;

procedure TForm23.Button1Click(Sender: TObject);
const
  g_macro = '{var1} should be equal to {Now()}';
begin
  with TROMacroParser.Create do try
    // register 'Now' function 
    RegisterProc('Now',Now,0);
    // register a variable
    AddVariable('var1').Value := DateTimeToStr(SysUtils.Now);    
    // evaluate macro
    ShowMessage(Eval(g_macro));  
  finally
    Free;
  end;
end;

Output: 26.02.2010 12:23:50 should be equal to 26.02.2010 12:23:50

Location


 

constructor Create

Creates a new instance.

constructor Create

AddVariable

Adds a variable.

function AddVariable(const Name: string): TROMacroVar

Parameters:

  • Name: variable name.

AllowComplexIdent  protected

property AllowComplexIdent: Boolean read write

AllowDoubleQuotedIdent  protected

property AllowDoubleQuotedIdent: Boolean read write

ClearProcs

Clear all procedures.

procedure ClearProcs

ClearVariables

Clear all variables.

procedure ClearVariables

DeleteVariable (TROMacroVar)  overload

procedure DeleteVariable(aVariable: TROMacroVar)

Parameters:

  • aVariable:

DeleteVariable (Integer)  overload

procedure DeleteVariable(I: Integer)

Parameters:

  • I:

Eval

Evaluates the given text.

function Eval(const Text: string; TextDelimiter: Char): string

Parameters:

  • Text:
  • TextDelimiter:

EvalToken

Evaluates a token.

function EvalToken(const Text: string): string

Parameters:

  • Text:

IndexOfName

Returns the position of the first name-value pair with the specified name.

function IndexOfName(const aName: string): Integer

Parameters:

  • aName: specified name

OnUnknownIdentifier

This event is fired when an unknown variable is detected.

property OnUnknownIdentifier: TOnUnknownIdentifier read write
delegate: function OnUnknownIdentifier(Sender: TObject; const Name: string; const OrgName: string; var Value: string): Boolean

OpenBlockEscape  protected

property OpenBlockEscape: Boolean read write

RegisterProc

Registers a procedure.

procedure RegisterProc(const Name: string; ExProc: TExternalProc; aParamCount: Integer)

Parameters:

  • Name:
  • ExProc:
  • aParamCount:

Variable

Returns the registered variable.

property Variable[I: Integer]: TROMacroVar read

VariableCount

Returns the count of variables.

property VariableCount: Integer read

 

AllowComplexIdent  protected

property AllowComplexIdent: Boolean read write

AllowDoubleQuotedIdent  protected

property AllowDoubleQuotedIdent: Boolean read write

OpenBlockEscape  protected

property OpenBlockEscape: Boolean read write

Variable

Returns the registered variable.

property Variable[I: Integer]: TROMacroVar read

VariableCount

Returns the count of variables.

property VariableCount: Integer read

 

constructor Create

Creates a new instance.

constructor Create

AddVariable

Adds a variable.

function AddVariable(const Name: string): TROMacroVar

Parameters:

  • Name: variable name.

ClearProcs

Clear all procedures.

procedure ClearProcs

ClearVariables

Clear all variables.

procedure ClearVariables

DeleteVariable (TROMacroVar)  overload

procedure DeleteVariable(aVariable: TROMacroVar)

Parameters:

  • aVariable:

DeleteVariable (Integer)  overload

procedure DeleteVariable(I: Integer)

Parameters:

  • I:

Eval

Evaluates the given text.

function Eval(const Text: string; TextDelimiter: Char): string

Parameters:

  • Text:
  • TextDelimiter:

EvalToken

Evaluates a token.

function EvalToken(const Text: string): string

Parameters:

  • Text:

IndexOfName

Returns the position of the first name-value pair with the specified name.

function IndexOfName(const aName: string): Integer

Parameters:

  • aName: specified name

RegisterProc

Registers a procedure.

procedure RegisterProc(const Name: string; ExProc: TExternalProc; aParamCount: Integer)

Parameters:

  • Name:
  • ExProc:
  • aParamCount:

 

OnUnknownIdentifier

This event is fired when an unknown variable is detected.

property OnUnknownIdentifier: TOnUnknownIdentifier read write
delegate: function OnUnknownIdentifier(Sender: TObject; const Name: string; const OrgName: string; var Value: string): Boolean