Class TRbwParser

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TRbwParser = class(TComponent)

Description

TRbwParser compiles expression in strings via the Compile method into TExpression objects that it owns.

It can also create TRealVariables, TIntegerVariables, TBooleanVariables, and TStringVariables that can be used in the TExpression via the CreateVariable method. Alternately, such variables created by another instance of TRbwParser can be used via the RegisterVariable method.

All variables and expressions created by an instance of TRbwParser are owned by it.

If several TRbwParsers are used and variables owned by one are used in another one, ClearExpressions and ClearVariables should be called in all of them before any of them is destroyed.

See TFunctionStringList and OverloadedFunctionList for a list of the functions included by default.

Hierarchy

Overview

Fields

Private Operators: TStringList;
Private WordOperators: TStringList;
Private Signs: set of AnsiChar;
Private FSpecialImplementorList: TSpecialImplementorList;
Private FCurrentExpression: TExpression;
Private FExpressions: TStringList;
Private FFunctions: TFunctionStringList;
Private FVariables: TStringList;
Private FOwnedVariables: TObjectList;
Private FOpereratorDefinitions: TList;
Private FCachedFindResult: integer;

Methods

Private function GetExpressions(const Index: integer): TExpression;
Private function GetVariable(const Index: integer): TCustomValue;
Private procedure DefineNotOperator;
Private procedure DefinePlusSignOperator;
Private procedure DefineMinusSignOperator;
Private procedure DefineTimesOperator;
Private procedure DefineDivideOperator;
Private procedure DefineDivOperator;
Private procedure DefineModOperator;
Private procedure DefineAndOperator;
Private procedure DefinePlusOperator;
Private procedure DefineMinusOperator;
Private procedure DefineOrOperator;
Private procedure DefineXorOperator;
Private procedure DefineEqualsOperator;
Private procedure DefineNotEqualsOperator;
Private procedure DefineLessThanOperator;
Private procedure DefineGreaterThanOperator;
Private procedure DefineLessThanOrEqualsOperator;
Private procedure DefineGreaterThanOrEqualsOperator;
Public procedure AddOperator(OpDef: TOperatorDefinition);
Public procedure RemoveOperator(OperatorName: AnsiString);
Public procedure ClearExpressions;
Public procedure ClearVariables;
Public function CreateVariable(const Name, Classification: string; const Value: boolean; const NameToDisplay: string): TBooleanVariable; overload;
Public function CreateVariable(const Name, Classification: string; const Value: boolean; VariableClass: TBooleanVariableClass; const NameToDisplay: string): TBooleanVariable; overload;
Public function CreateVariable(const Name, Classification: string; const Value: integer; const NameToDisplay: string): TIntegerVariable; overload;
Public function CreateVariable(const Name, Classification: string; const Value: integer; VariableClass: TIntegerVariableClass; const NameToDisplay: string) : TIntegerVariable; overload;
Public function CreateVariable(const Name, Classification: string; const Value: double; const NameToDisplay: string): TRealVariable; overload;
Public function CreateVariable(const Name, Classification: string; const Value: double; VariableClass: TRealVariableClass; const NameToDisplay: string): TRealVariable; overload;
Public function CreateVariable(const Name, Classification: string; const Value: string; const NameToDisplay: string): TStringVariable; overload;
Public function CreateVariable(const Name, Classification: string; const Value: string; VariableClass: TStringVariableClass; const NameToDisplay: string): TStringVariable; overload;
Public function Compile(var AString: string): integer;
Public constructor Create(AOwner: TComponent); override;
Public procedure DeleteExpression(const Index: integer);
Public destructor Destroy; override;
Public function ExpressionCount: integer;
Public function IndexOfVariable(VariableName: string): integer;
Public procedure RegisterVariable(const Value: TCustomValue);
Public procedure RemoveExpression(const Expression: TExpression);
Public procedure RemoveVariable(const Variable: TCustomVariable);
Public procedure RenameVariable(var Index: integer; NewName: string; NewDisplayName: string);
Public function VariableCount: integer;

Properties

Public property SpecialImplementorList: TSpecialImplementorList read FSpecialImplementorList;
Public property CurrentExpression: TExpression read FCurrentExpression;
Public property Expressions[constIndex:integer]: TExpression read GetExpressions;
Public property Functions: TFunctionStringList read FFunctions;
Public property Variables[constIndex:integer]: TCustomValue read GetVariable;

Description

Fields

Private Operators: TStringList;

Operators contains the names of the single character operators.

Private WordOperators: TStringList;

name contains the names of the operators that have two or more characters in their names.

Private Signs: set of AnsiChar;

Signs contains the names of the sign operators.

Private FSpecialImplementorList: TSpecialImplementorList;

See TSpecialImplementorList and SpecialImplementorList.

Private FCurrentExpression: TExpression;

FCurrentExpression: TExpression; See CurrentExpression.

Private FExpressions: TStringList;

FExpressions: TStringList; See Expressions.

Private FFunctions: TFunctionStringList;

FFunctions: TFunctionStringList; See Functions.

Private FVariables: TStringList;

FVariables: TStringList; See Variables.

Private FOwnedVariables: TObjectList;

FOwnedVariables: TObjectList; FOwnedVariables holds all the TCustomVariables owned by the TRbwParser.

Private FOpereratorDefinitions: TList;

FOpereratorDefinitions contains a series of TOperatorDefinitions.

Private FCachedFindResult: integer;
 

Methods

Private function GetExpressions(const Index: integer): TExpression;

See Expressions.

Private function GetVariable(const Index: integer): TCustomValue;

See Variables.

Private procedure DefineNotOperator;

DefineNotOperator defines the "not" operator.

Private procedure DefinePlusSignOperator;

DefinePlusSignOperator defines the "+" sign operator.

Private procedure DefineMinusSignOperator;

DefineMinusSignOperator defines the "-" sign operator.

Private procedure DefineTimesOperator;

DefineTimesOperator defines the "*" operator.

Private procedure DefineDivideOperator;

DefineDivideOperator defines the "/" operator.

Private procedure DefineDivOperator;

DefineDivOperator defines the "div" operator.

Private procedure DefineModOperator;

DefineModOperator defines the "mod" operator.

Private procedure DefineAndOperator;

DefineAndOperator defines the "and" operator.

Private procedure DefinePlusOperator;

DefinePlusOperator defines the "+" (addition or concatenation) operator.

Private procedure DefineMinusOperator;

DefineMinusOperator defines the "-" (subtraction) operator.

Private procedure DefineOrOperator;

DefineOrOperator defines the "or" operator.

Private procedure DefineXorOperator;

DefineXorOperator defines the "xor" operator.

Private procedure DefineEqualsOperator;

DefineEqualsOperator defines the "=" operator.

Private procedure DefineNotEqualsOperator;

DefineNotEqualsOperator defines the "<>" operator.

Private procedure DefineLessThanOperator;

DefineLessThanOperator defines the "<" operator.

Private procedure DefineGreaterThanOperator;

DefineGreaterThanOperator defines the ">" operator.

Private procedure DefineLessThanOrEqualsOperator;

DefineLessThanOrEqualsOperator defines the "<=" operator.

Private procedure DefineGreaterThanOrEqualsOperator;

DefineGreaterThanOrEqualsOperator defines the ">=" operator.

Public procedure AddOperator(OpDef: TOperatorDefinition);

AddOperator adds an operator to the operators recognized by TRbwParser. The TRbwParser will take ownership of the TOperatorDefinition but not of any TOperatorArgumentDefinition that it has.

Public procedure RemoveOperator(OperatorName: AnsiString);

RemoveOperator will remove the TOperatorDefinition whose OperatorName is OperatorName.

Public procedure ClearExpressions;

ClearExpressions destroys all compiled TExpressions in the TRbwParser.

If several TRbwParsers are used and variables owned by one are used in another one, ClearExpressions and ClearVariables should be called in all of them before any of them is destroyed.

Public procedure ClearVariables;

ClearVariables removes all variables from the list of variables used by TRbwParser but does not free them (because they may be used by another TRbwParser).

If several TRbwParsers are used and variables owned by one are used in another one, ClearExpressions and ClearVariables should be called in all of them before any of them is destroyed.

Public function CreateVariable(const Name, Classification: string; const Value: boolean; const NameToDisplay: string): TBooleanVariable; overload;

CreateVariable creates a TBooleanVariable owned by TRbwParser and allows it to be used with the TRbwParser.

See also: RegisterVariable.

Public function CreateVariable(const Name, Classification: string; const Value: boolean; VariableClass: TBooleanVariableClass; const NameToDisplay: string): TBooleanVariable; overload;
 
Public function CreateVariable(const Name, Classification: string; const Value: integer; const NameToDisplay: string): TIntegerVariable; overload;

CreateVariable creates a TIntegerVariable owned by TRbwParser and allows it to be used with the TRbwParser.

See also: RegisterVariable.

Public function CreateVariable(const Name, Classification: string; const Value: integer; VariableClass: TIntegerVariableClass; const NameToDisplay: string) : TIntegerVariable; overload;
 
Public function CreateVariable(const Name, Classification: string; const Value: double; const NameToDisplay: string): TRealVariable; overload;

CreateVariable creates a TRealVariable owned by TRbwParser and allows it to be used with the TRbwParser.

See also: RegisterVariable.

Example:

      procedure TForm1.Button2Click(Sender: TObject);
      var
        Index : integer;
        Variable : TRealVariable;
      begin
        RbwParser1.CreateVariable('A', 2.5);
        RbwParser1.CreateVariable('B', 3.5);
        RbwParser1.Compile('A + B');
        RbwParser1.CurrentExpression.Evaluate;
        Label1.Caption := 'result: '
          + FloatToStr(RbwParser1.CurrentExpression.DoubleResult);
        // Label1.Caption is set to "result: 6".
        Index := RbwParser1.IndexOfVariable('a');
        // variable names are not case sensitive.
        Variable := RbwParser1.Variables[Index] as TRealVariable;
        Variable.Value := 6.5;

        RbwParser1.CurrentExpression.Evaluate;
        Label2.Caption := 'result: '
          + FloatToStr(RbwParser1.CurrentExpression.DoubleResult);
        // Label2.Caption is set to "result: 10".
        // As it stands, this event handler would cause
        // an error if it was called twice because
        // it would try to create variables named "A" and "B" twice.
        // Calling ClearVariables would prevent this if that is
        // what you really want to do.
      end;
      

Public function CreateVariable(const Name, Classification: string; const Value: double; VariableClass: TRealVariableClass; const NameToDisplay: string): TRealVariable; overload;
 
Public function CreateVariable(const Name, Classification: string; const Value: string; const NameToDisplay: string): TStringVariable; overload;

CreateVariable creates a TStringVariable owned by TRbwParser and allows it to be used with the TRbwParser.

See also: RegisterVariable.

Public function CreateVariable(const Name, Classification: string; const Value: string; VariableClass: TStringVariableClass; const NameToDisplay: string): TStringVariable; overload;
 
Public function Compile(var AString: string): integer;

Compile searches for AString in Expressions. If it finds it, it sets CurrentExpression to that TExpression and returns it's position in Expressions. If it doesn't find it, Compile converts AString into a TExpression, sets CurrentExpression to the TExpression it created, adds the TExpression to Expressions and returns the position of the TExpression in Expressions.

Expressions are owned by TRbwParser.

Public constructor Create(AOwner: TComponent); override;

Create creates an instance of TRbwParser;

Public procedure DeleteExpression(const Index: integer);

DeleteExpression destroys the TExpression at Index and deletes it from the list of Expressions.

Public destructor Destroy; override;

Destroy destroys the TRbwParser. Do not call Destroy directly. Call Free instead.

Public function ExpressionCount: integer;

ExpressionCount returns the number of TExpressions in Expressions.

Public function IndexOfVariable(VariableName: string): integer;

IndexOfVariable locates the TCustomVariable whose name is VariableName in Variables and returns it's position. If it is not in Variables it returns -1.

Public procedure RegisterVariable(const Value: TCustomValue);

RegisterVariable allows a TCustomValue to be used by the TRbwParser even though the TCustomValue isn't owned by the TRbwParser.

Public procedure RemoveExpression(const Expression: TExpression);

RemoveExpression deletes Expression from the list of Expressions and destroys it.

Public procedure RemoveVariable(const Variable: TCustomVariable);

If Variable is owned by or registered with TRbwParser, RemoveVariable removes it and, if it is owned by the current instance of TRbwParser, also destroys it. It also destroys any TExpressions in the current TRbwParser that use Variable.

Public procedure RenameVariable(var Index: integer; NewName: string; NewDisplayName: string);

RenameVariable changes the name of the variable at position Index to a NewName and changes Index to the new position of the variable.

Public function VariableCount: integer;

VariableCount is the number of variables in Variables.

Properties

Public property SpecialImplementorList: TSpecialImplementorList read FSpecialImplementorList;

See: TSpecialImplementorList.

Public property CurrentExpression: TExpression read FCurrentExpression;

CurrentExpression is the most recently Compiled TExpression.

Public property Expressions[constIndex:integer]: TExpression read GetExpressions;

Expressions is an array of TExpressions.

Public property Functions: TFunctionStringList read FFunctions;

Functions stores TFunctionClasses in it's Objects property and manages the TFunctionClasses used by TRbwParser.

Public property Variables[constIndex:integer]: TCustomValue read GetVariable;

Variables is an array of variables (TCustomValues) used by the current TRbwParser.


Generated by PasDoc 0.12.1 on 2013-05-13 15:42:00