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 FCurrentExpression: TExpression;
Private FExpressions: TStringList;
Private FFunctions: TFunctionStringList;
Private FVariables: TStringList;
Private FOwnedVariables: TObjectList;

Methods

Private function GetExpressions(const Index: integer): TExpression;
Private function GetVariable(const Index: integer): TCustomValue;
Public procedure ClearExpressions;
Public procedure ClearVariables;
Public function CreateVariable(const Name: string; const Value: boolean): TBooleanVariable; overload;
Public function CreateVariable(const Name: string; const Value: integer): TIntegerVariable; overload;
Public function CreateVariable(const Name: string; const Value: double): TRealVariable; overload;
Public function CreateVariable(const Name: string; const Value: 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);
Public function VariableCount: integer;

Properties

Public property CurrentExpression: TExpression read FCurrentExpression;
Public property Expressions[const Index: integer]: TExpression read GetExpressions;
Public property Functions: TFunctionStringList read FFunctions;
Public property Variables[const Index: integer]: TCustomValue read GetVariable;

Description

Fields

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.

Methods

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

See Expressions.

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

See Variables.

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: string; const Value: boolean): 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: string; const Value: integer): 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: string; const Value: double): 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: string; const Value: string): TStringVariable; overload;

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

See also: RegisterVariable.

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);

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 CurrentExpression: TExpression read FCurrentExpression;

CurrentExpression is the most recently Compiled TExpression.

Public property Expressions[const Index: 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[const Index: integer]: TCustomValue read GetVariable;

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


Generated by PasDoc 0.10.0 on 2006-10-31 09:56:45