|Top Previous Next|
property Expression : string ;
Expression property represents the mathematical expression which is input to be evaluated by the user.
The expression can contain variables such as X, Y, T, HEIGHT, WEIGHT and so on. Expression can also contain functions that take one parameter, two parameters or any number of parameters. Expressions are case insensitive. Internally they are converted to uppercase before parsing.
When Expression is assigned a value, it becomes 'dirty' and further attempt to evaluate its value will require it to be parsed. But once it is parsed, and a parse tree representing the expression is formed, it won't be parsed again, until it is assigned a new string. Instead, the parse tree will be used to retrieve current results as the values of variables change.
X, Y and PI variables are predefined and can be immediately used in the expression (If you don't want them, you can delete with DeleteVar). CreateVar method can be used to add user variables. Variables do not have to be predefined. You can choose to implement OnVariableFound event handler. If OnVariableFound event handler is assigned, then it will be invoked to retrieve values for undefined variables.
Predefined functions that take one parameter are:
SQR: Square function which can be used as SQR(X)
SIN: Sinus function which can be used as SIN(X), X is a real-type expression. Sin returns the sine of the angle X in radians.
COS: Cosinus function which can be used as COS(X), X is a real-type expression. COS returns the cosine of the angle X in radians.
ATAN: ArcTangent function which can be used as ATAN(X)
SINH: Sinus Hyperbolic function which can be used as SINH(X)
COSH: Cosinus Hyperbolic function which can be used as COSH(X)
COTAN: which can be used as COTAN(X)
TAN: which can be used as TAN(X)
EXP: which can be used as EXP(X)
LN: natural log, which can be used as LN(X)
LOG: 10 based log, which can be used as LOG(X)
SQRT: which can be used as SQRT(X)
ABS: absolute value, which can be used as ABS(X)
SIGN: SIGN(X) returns -1 if X<0; +1 if X>0, 0 if X=0; it can be used as SQR(X)
TRUNC: Discards the fractional part of a number. e.g. TRUNC(-3.2) is -3, TRUNC(3.2) is 3.
CEIL: CEIL(-3.2) = 3, CEIL(3.2) = 4
FLOOR: FLOOR(-3.2) = -4, FLOOR(3.2) = 3
RND: Random number generator.
RND(X) generates a random INTEGER number such that 0 <= Result < int(X). Call TbcParser.Randomize to initialize the random number generator with a random seed value before using RND function in your expression.
RANDOM: Random number generator.
RANDOM(X) generates a random floating point number such that 0 <= Result < X. Call TbcParser.Randomize to initialize the random number generator with a random seed value before using RANDOM function in your expression.
Predefined functions that take two parameters are:
INTPOW: The INTPOW function raises Base to an integral power. INTPOW(2, 3) = 8. Note that result of INTPOW(2, 3.4) = 8 as well.
POW: The Power function raises Base to any power. For fractional exponents or exponents greater than MaxInt, Base must be greater than 0.
LOGN: The LogN function returns the log base N of X. Example: LOGN(10, 100) = 2
MIN: MIN(2, 3) is 2.
MAX: MAX(2, 3) is 3.
Predefined functions that take more than 2 parameters are:
IF: IF(BOOL, X, Y) returns X if BOOL is <> 0, returns Y if BOOL =0. Values of X and Y are calculated regardless of BOOL (Full Boolean Evaluation).
User functions can be added using CreateOneParamFunc, CreateTwoParamFunc and CreateNParamFunc methods. Functions and Variables can be deleted using DeleteVar, DeleteFunc, DeleteAllVars, DeleteAllFuncs methods.