Which functions are predefined in JCL TEvaluator class

雨燕双飞 提交于 2020-01-13 11:00:11

问题


Does anyone know which predefined functions (e.g ABS function) are included in the TEvaluator JCL class for Delphi 7?


回答1:


There are none of the standard functions from Math.pas included. All that is implemented in the default evaluation parser are the operators or, xor, and, not, mod, +, -, /, *, <, >, <=, >=, =, div, cmp, bor, bxor, band, bnot, shl, and shr. (As many as I found in a quick check of the source, and a few I missed based on @David's comment.)

You can add functions (including those that are part of the Delphi RTL) to the evaluator fairly easily. It's even shown in the demo, which adds the functions from one of the JCL units.

The JCL evaluator example (ExprEvalExample.dpr) found by default in the JCL\examples\common\expreval folder passes a TComboBox.Items to the Init function in ExprEvalExampleLogic.pas as the FuncList parameter, which is populated by this code (the TEasyEvaluator is given the functions in the same routine) with the functions from JclMath.pas:

  with FuncList do
  begin
    Add('LogBase10');
    Add('LogBase2');
    Add('LogBaseN');
    Add('ArcCos');
    Add('ArcCot');
    Add('ArcCsc');
    Add('ArcSec');
    Add('ArcSin');
    Add('ArcTan');
    Add('ArcTan2');
    Add('Cos');
    Add('Cot');
    Add('Coversine');
    Add('Csc');
    Add('Exsecans');
    Add('Haversine');
    Add('Sec');
    Add('Sin');
    Add('Tan');
    Add('Versine');
    Add('ArcCosH');
    Add('ArcCotH');
    Add('ArcCscH');
    Add('ArcSecH');
    Add('ArcSinH');
    Add('ArcTanH');
    Add('CosH');
    Add('CotH');
    Add('CscH');
    Add('SecH');
    Add('SinH');
    Add('TanH');
  end;

Those would be the functions supported in the demo app. You can add your own in a similar fashion.




回答2:


No predefined functions are included. There are the standard arithmetic operators: +, -, *, div and mod. And there's all the standard logical and bitwise operators. But nothing like abs, sin, exp, log etc. You have to put those in yourself. It is trivially easy to add functions and I think it's a good design to let you choose exactly what your evaluator supports.



来源:https://stackoverflow.com/questions/13592136/which-functions-are-predefined-in-jcl-tevaluator-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!