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.

ClearProcs

Clear all procedures.

procedure ClearProcs

ClearVariables

Clear all variables.

procedure ClearVariables

DeleteVariable (Integer)  overload

procedure DeleteVariable(I: Integer)

Parameters:

  • I:

DeleteVariable (TROMacroVar)  overload

procedure DeleteVariable(aVariable: TROMacroVar)

Parameters:

  • aVariable:

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

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 write

VariableCount

Returns the count of variables.

property VariableCount: Integer read write

 

Variable

Returns the registered variable.

property Variable[I: Integer]: TROMacroVar read write

VariableCount

Returns the count of variables.

property VariableCount: Integer read write

 

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 (Integer)  overload

procedure DeleteVariable(I: Integer)

Parameters:

  • I:

DeleteVariable (TROMacroVar)  overload

procedure DeleteVariable(aVariable: TROMacroVar)

Parameters:

  • aVariable:

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

Descendants

See Also