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
- Unit: uDAMacros.pas
- Ancestry: TDAInterfacedObject | TROMacroParser
constructor Create
Creates a new instance.
constructor Create
AddVariable
Adds a variable.
function AddVariable(const Name: string): TROMacroVar
Parameters:
- Name: variable name.
AllowComplexIdent protected
Allows complex identificators, like "table"."name"
property AllowComplexIdent: Boolean read write
AllowDoubleQuotedIdent protected
Allows double quoted identificators, like "field"
property AllowDoubleQuotedIdent: Boolean read write
ClearProcs
Clear all procedures.
procedure ClearProcs
ClearVariables
Clear all variables.
procedure ClearVariables
DeleteVariable (TROMacroVar) overload
Deletes variable
procedure DeleteVariable(aVariable: TROMacroVar)
Parameters:
- aVariable: variable
DeleteVariable (Integer) overload
Deletes variable by index
procedure DeleteVariable(I: Integer)
Parameters:
- I: index
Eval
Evaluates the given text.
function Eval(const Text: string; TextDelimiter: Char = ''''): string
Parameters:
- Text: text
- TextDelimiter: delimiter
EvalToken
Evaluates a token.
function EvalToken(const Text: string): string
Parameters:
- Text: token
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
Allow to use square brackets for identificators, i.e. [something]
property OpenBlockEscape: Boolean read write
QueryInterface protected stdcall (declared in TDAInterfacedObject)
Implements the IInterfaceQueryInterface method.
function QueryInterface(const IID: TGUID; out Obj: ): HResult
Parameters:
- IID: Identifier of the interface to return
- Obj: Variable to store the returned interface reference to
RefCount protected (declared in TDAInterfacedObject)
Returns 0
property RefCount: Integer read
RegisterProc
Registers a procedure.
procedure RegisterProc(const Name: string; ExProc: TExternalProc; aParamCount: Integer)
Parameters:
- Name: Name
- ExProc: Method
- aParamCount: Parameters count
Variable
Returns the registered variable.
property Variable[I: Integer]: TROMacroVar read
VariableCount
Returns the count of variables.
property VariableCount: Integer read
AllowComplexIdent protected
Allows complex identificators, like "table"."name"
property AllowComplexIdent: Boolean read write
AllowDoubleQuotedIdent protected
Allows double quoted identificators, like "field"
property AllowDoubleQuotedIdent: Boolean read write
OpenBlockEscape protected
Allow to use square brackets for identificators, i.e. [something]
property OpenBlockEscape: Boolean read write
RefCount protected (declared in TDAInterfacedObject)
Returns 0
property RefCount: Integer read
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
Deletes variable
procedure DeleteVariable(aVariable: TROMacroVar)
Parameters:
- aVariable: variable
DeleteVariable (Integer) overload
Deletes variable by index
procedure DeleteVariable(I: Integer)
Parameters:
- I: index
Eval
Evaluates the given text.
function Eval(const Text: string; TextDelimiter: Char = ''''): string
Parameters:
- Text: text
- TextDelimiter: delimiter
EvalToken
Evaluates a token.
function EvalToken(const Text: string): string
Parameters:
- Text: token
IndexOfName
Returns the position of the first name-value pair with the specified name.
function IndexOfName(const aName: string): Integer
Parameters:
- aName: specified name
QueryInterface protected stdcall (declared in TDAInterfacedObject)
Implements the IInterfaceQueryInterface method.
function QueryInterface(const IID: TGUID; out Obj: ): HResult
Parameters:
- IID: Identifier of the interface to return
- Obj: Variable to store the returned interface reference to
RegisterProc
Registers a procedure.
procedure RegisterProc(const Name: string; ExProc: TExternalProc; aParamCount: Integer)
Parameters:
- Name: Name
- ExProc: Method
- aParamCount: Parameters count
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