QuickLib
QuickLib copied to clipboard
QuickLib.Expression have bug and Some advice
First, it was found that priority processing was not supported, causing some partial errors: Assert(true, TExpressionParser.Validate(5, '(0.3 < 8) or (5 < 4) and (2 = 1)')); //false is err Assert(true, TExpressionParser.Validate(5, '(8 > 3) or (5 > 4) and (2 = 1)')); //false is err
Some statements cannot be executed // PRN(TExpressionParser.Validate(5,'8<1')); // PRN(TExpressionParser.Validate(5,'8 < 1 or 5 > 4 '));
Unable to support addition, subtraction, multiplication and division. Hope to support common functions as well as custom functions
Sorry, as you can see in readme, TExpressionParser was created to validate object properties. You need to pass and object as first parameter, and an expression as second param, where each condition can be a property or a property of a property of that object:
if TExpressionParser.Validate(user,('(Age > 30) AND (Dept.Name = "Financial")') then
begin
//do something
end;
But, if you pass a integer as first param, TExpression replaces first part of every condition with that integer.
TExpressionParser.Validate(20,('(a > 30) AND (a < 40)') //will be transformed as (20 > 30) AND (20 < 40)
TExpressionParser.Validate(5,('(8,3 > 2) AND (50 < 40)') //will be transformed as (5 > 2) AND (5 < 40)
However, I updated Expressions to support Validate without first param: `` TExpressionParser.Validate(''(8 > 3) or ((5 > 4) and (2 = 1))')
Priority in TExpressions are defined with parenthesis. Expressions are processed from outer to inner parenthesis and from left to right. See new sample in QuickLib\samples\delphi.
Thanks for your guidance. In fact, I also made a similar module, it can also do expression evaluation, and without the need for logical expressions with parentheses and the operator and support addition, subtraction, multiplication and division operations, do you have any plans to expand your current module? If you are interested, I can send it to you for reference.
Yes, of course.
Attached is the file, please receive it. Calc.zip