DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: cuiqingbo
今日帖子: 20
在线用户: 15
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 hbug (hbug) ★☆☆☆☆ -
普通会员
2020/8/26 11:42:21
标题:
delphi有没有好用的四则运算表达式? 浏览:2167
加入我的收藏
楼主: 各位老友,delphi有没有好用的四则运算表达式解析器,能否推荐一个成熟的控件.
----------------------------------------------
专业提供人力资源软件、指纹考勤软件、POS进销存软件、酒店餐饮软件
http://www.winsoftcn.com
作者:
男 wang_80919 (Flying Wang) ★☆☆☆☆ -
普通会员
2020/8/26 12:08:42
1楼: 我记得,新版本好像有一个。可能是我记错了。
也许 新版本 内置的是 简单的 正则表达式。
----------------------------------------------
(C)(P)Flying Wang
作者:
男 star5 (星五) ★☆☆☆☆ -
盒子活跃会员
2020/8/26 12:25:58
2楼: 用法:
AFormula := utFormula.TFormula.Create;
  try
      xx := AFormula.calc(xxx);
  finally
    AFormula.Free;
  end;
此帖子包含附件:star5_2020826122558.txt 大小:6.6K
----------------------------------------------
博客 - http://offeu.com
脚本模型 - http://webpascal.com
需要短信接口的请联系我,可发行业与营销内容。
作者:
男 star5 (星五) ★☆☆☆☆ -
盒子活跃会员
2020/8/26 12:27:09
3楼: 项目中用过,效果不错,具体哪来的忘了。。。
----------------------------------------------
博客 - http://offeu.com
脚本模型 - http://webpascal.com
需要短信接口的请联系我,可发行业与营销内容。
作者:
男 lps (lps) ★☆☆☆☆ -
盒子活跃会员
2020/8/26 12:38:14
4楼: 最好的方案:1、调用脚本,2、数据库。原因:这两个是经过检验的。
一个例子:
https://blog.csdn.net/fyl_077/article/details/49929335
不要去找控件,因为软件质量真不好说
----------------------------------------------
-
作者:
男 sdzzb (一刀) ▲▲▲▲▲ -
普通会员
2020/8/26 12:51:27
5楼: FatExpression还行
此帖子包含附件:sdzzb_2020826125230.zip 大小:220.7K
----------------------------------------------
-
作者:
男 bahamut8348 (leonna) ★☆☆☆☆ -
普通会员
2020/8/26 12:59:43
6楼: https://github.com/cnpack/cnvcl/blob/master/Source/Common/CnCommon.pas

EvalSimpleExpression
----------------------------------------------
--
作者:
男 iamdream (银河恒久远,梦想无止境!) ★☆☆☆☆ -
大贡献会员
2020/8/26 13:32:10
7楼: 用FastReport中带的FastScript吧,万一哪天想扩展功能也不用换。我之前的公司用这个很多年了,比较稳定。
----------------------------------------------
-广袤璀璨的银河,永无止境的梦想(梦无止境游银河) 博客挂了……
作者:
男 hbug (hbug) ★☆☆☆☆ -
普通会员
2020/8/26 14:07:01
8楼: 谢谢各位老铁。 :)
----------------------------------------------
专业提供人力资源软件、指纹考勤软件、POS进销存软件、酒店餐饮软件
http://www.winsoftcn.com
作者:
男 luckyrandom (luckyrandom) ★☆☆☆☆ -
普通会员
2020/8/26 14:48:02
9楼: 借用数据库是好方案,自己去解析很麻烦
----------------------------------------------
SQL SERVER DBA QQ:315054403 曾经的Delphier  缘在上海
作者:
男 hbug (hbug) ★☆☆☆☆ -
普通会员
2020/8/26 14:51:43
9楼: 原来做工资考勤系统用的是这个解析器

http://www.2ccc.com/article.asp?articleid=2370


用着还不错,但是感觉计算速度不够快,想看看有没有替代品,不知道有没有同行用pax compile 做脚本解析的,用于考勤计算方面,欢迎交流交流.
----------------------------------------------
专业提供人力资源软件、指纹考勤软件、POS进销存软件、酒店餐饮软件
http://www.winsoftcn.com
作者:
男 lps (lps) ★☆☆☆☆ -
盒子活跃会员
2020/8/26 16:08:19
10楼: 不明白为什么追求速度?!
脚本或数据库的方案是确保正确性。如果只有简单的几种表达式,建议自己写,这样也能保证速度
----------------------------------------------
-
作者:
男 hbug (hbug) ★☆☆☆☆ -
普通会员
2020/8/26 16:35:04
11楼: @lps 考勤计算速度越快当然越好了。原来我的公式这样的
旷工天數=
iif((日常出勤表.事假分钟+日常出勤表.病假分钟+日常出勤表.产假分钟+日常出勤表.丧假分钟+日常出勤表.婚假分钟+日常出勤表.生理假分钟+日常出勤表.工伤假分钟)>0,0,iif(日常出勤表.有薪假标志='有薪',0,iif(日常出勤表.工作日标志='0',(iif((日常出勤表.年假分钟+日常出勤表.补休分钟+日常出勤表.上班分钟)<=240,1-(iif((日常出勤表.年假分钟+日常出勤表.补休分钟+日常出勤表.上班分钟)>=480,480,(日常出勤表.年假分钟+日常出勤表.补休分钟+日常出勤表.上班分钟))/60/8),0))),0)))
扣缺勤工资=
round(iif((工资.事假缺勤工时+工资.病假缺勤工时+工资.法定年休假缺勤工时+工资.婚产丧假缺勤工时+工资.旷工缺勤工时)>(21.75*8),(21.75*8),(工资.事假缺勤工时+工资.病假缺勤工时+工资.法定年休假缺勤工时+工资.婚产丧假缺勤工时+工资.旷工缺勤工时)),1) 类似这样的

然后把上面的项目替换成具体的数字,再用解析器计算出结果给我,(感觉这方法笨笨的),好处就是用户也可以自定义工资项目及计算方法,不好的地方就是一条记录一条记录计算完保存,数据多了计算速度就慢了,用数据库的方案是自己写SQL脚本吗?好是好,但客户不会用sql ,感觉不灵活。
----------------------------------------------
专业提供人力资源软件、指纹考勤软件、POS进销存软件、酒店餐饮软件
http://www.winsoftcn.com
作者:
男 lps (lps) ★☆☆☆☆ -
盒子活跃会员
2020/8/26 16:44:02
12楼: 数据库方案是sql中可以包含表达式(甚至是独立的表达式也可以用sql求值),客户只要按sql要求的语法规则写表达式就行了,并不是写sql!

速度问题我认为应该这样处理:一次处理很多记录是不对的,这么搞无论如何都快不起来!应该是每条记录录入或修改时就进行计算,这样速度根本不重要了。举一个反面例子(但不是人家技术不行哈):高考录取,按批次出档,每回都要数小时,原因就在一次要处理很多记录
----------------------------------------------
-
作者:
男 hbug (hbug) ★☆☆☆☆ -
普通会员
2020/8/26 16:54:56
13楼: @lps能不能参考一下你写的sql 表达式,我看看是什么样的 ?
----------------------------------------------
专业提供人力资源软件、指纹考勤软件、POS进销存软件、酒店餐饮软件
http://www.winsoftcn.com
作者:
男 lps (lps) ★☆☆☆☆ -
盒子活跃会员
2020/8/26 16:57:42
13楼: 补充两句:
    1、楼主本身就是数据库应用,所以直接使用数据库中sql对表达式的支持应该是最佳的;
    2、按10楼及其他描述,楼主应该是一次处理多条记录,并且使用delphi中表达式计算,也就是说不是在server端直接计算的,是先取数据传输到客户端,然后计算,完了可能还要回传服务器。个人认为以上方法是很差的设计!为什么不能在server端直接计算呢?比如搞一个存储过程处理这个,另外旷工的毕竟是少数,所以一个建议方案是搞一个旷工表:如果确实旷工就记录在表中,这样遍历一次也没多少条记录
----------------------------------------------
-
作者:
男 lps (lps) ★☆☆☆☆ -
盒子活跃会员
2020/8/26 16:58:49
14楼: select 表达式 as f1 from 表名

就这样写就可以对表达式求值了
----------------------------------------------
-
作者:
男 hbug (hbug) ★☆☆☆☆ -
普通会员
2020/8/26 17:16:31
15楼: 确实是在客户端计算完,再存回去的,但是让客户写 select 表达式 as f1 from 表名 这样的,比较难,你想想,工资项目每个公司都是不一样的,计算方法也不一样的,如果是给客户定制,项目包括计算方公是确定的,我都可以直接在后台sql处理,这样更快。
----------------------------------------------
专业提供人力资源软件、指纹考勤软件、POS进销存软件、酒店餐饮软件
http://www.winsoftcn.com
作者:
男 lps (lps) ★☆☆☆☆ -
盒子活跃会员
2020/8/26 17:59:01
16楼: 最后回复一次:1、客户只需要写表达式!组装成sql是程序的事,你试一下先;2、存储过程是可以有参数的,你不知道吗?表达式作为参数,完美!
----------------------------------------------
-
作者:
男 hbug (hbug) ★☆☆☆☆ -
普通会员
2020/8/27 7:52:12
17楼: @lps 谢谢回复。
----------------------------------------------
专业提供人力资源软件、指纹考勤软件、POS进销存软件、酒店餐饮软件
http://www.winsoftcn.com
作者:
男 dengjiyun (流云) ★☆☆☆☆ -
普通会员
2020/8/27 9:02:55
18楼: ArtFormula v1.5 for Delphi and Lazarus

ArtFormula package contains two nonvisual Delphi component for symbolic expression parsing and evaluation. Provides runtime scripting engine for automating your programs. Also ArtFormula can symbolically evaluate derivatives of a function with basic simplification of a result.

TArtFormula description

Properties:

property Error : TFormulaError; - returns current error code.

TFormulaError = (ER_Ok, ER_ILLEGAL, ER_UNKNOWN, ER_RIGHT, ER_LEFT, ER_SYNTAX, ER_VARS, ER_NOTENOUGH);

property ErrPos : integer; - returns position of error.

property ErrLine : integer; - returns the line with error.

property ErrStrPos : integer; - returns the position of error inside source string.

property Stop : boolean; - set Stop to true during computation to stop.

property Compiled : string; - byte code of compiled source string.

property LocalStrings : TStrings; - if TArtFormula compiled with multilang support (see below), this property contains list of pairs "StringName=LocalValue". You can use Names and Values properties of LocalStings to obtain string names and local values.

Published properties:

property UnQuotedString : boolean; - if true, ArtFormula will consider unknown identifiers as string literals.

property TestUsedVars : boolean; - if true, ArtFormula will test whether all external variables, passed as vars parameter of Compile or Test procedure, are used in source expression.

property CaseSensitive : boolean; - if true, ArtFormula will distinguish case of characters in variables name. Note: functions names are always case insensitive.

property Step : boolean; - if true, you can stop computation, by setting Stop property to true. If false you can't stop computation until it ends.

property CaseSensitiveString : boolean; - if true, ArtFormula will distinguish case of string characters in comparison operations and in pos function.

property ExternGetVar : boolean; - if set, ArtFormula will use GetVarValue and GetVarsCount events to evaluate unspecified external variables.

property VarNameLiterals : string; - defines set of literals, allowed for variable names.

property NoLeadingZero : boolean; - if true, you can omit leadin zero before point in floationg point numbers (both .5 and 0.5 correct), if false - only notation with leading zero accepted (only 0.5, .5 - causes error).

property ZeroEmptyString : boolean; - if true, ArtFormula will treat empty string az 0 in arithmetic operations.

Methods:

procedure SetVar(name : string; value : PCalcItem); - sets value of variable, given by name parameter.

function GetVar(name : string) : PCalcItem; - returns value of variable.

function IncVar(name : string) : PCalcItem; - increments value of a variable.

function DecVar(name : string) : PCalcItem; - decrements value of a variable.

procedure AddVar(name : string; value : PCalcItem); - adds internal variable.

procedure AddUserConstant(name, value : string); - adds new constant.

function AddUserFunction(name : string; paramcount:integer; fun : pformulafunction; ismodule:boolean=false):PTableItem; - adds user function (see Section creating user functions and modules).

function AddModuleFunction(module: PTableItem; name : string; paramcount:integer; fun : pformulafunction; ismodule:boolean=false):PTableItem; - adds module function (see Section creating user functions and modules).

function Test(instr : string; num : byte = 0; vars : PStringArray = nil) : boolean; - tests syntax of source code represented by instr. External variable names are passed as vars parameter, num specifies number of external variables. Returns true if there are no errors.

function Compile(instr : string; num : byte = 0; vars : PStringArray = nil) : string; - compiles source string and returns compiled byte code. On error raises exception.

function ComputeN(num : byte = 0; vals : PCalcArray = nil) : double; - compute previously compiled program and returns result as numeric value. Values of extern variables are passed in vals parameter, the number of values is passed in num value.

function Compute(num : byte = 0; vals : PCalcArray = nil) : string; - compute previously compiled program and returns result as string value.

function ComputeStrN(instr : string; num : byte = 0; vars : PStringArray = nil; vals : PCalcArray = nil) : double; - compiles and computes source string. Returns result as numeric value.

function ComputeStr(instr : string; num : byte = 0; vars : PStringArray = nil; vals : PCalcArray = nil) : string; - compiles and computes source string. Returns result as string value.

procedure StartGetVars(n : integer); - starts new parameters evaluation for variable argument list function (see Section creating user functions and modules).

function GetNextVar(var x : TCalcItem) : boolean; - evaluates next variable argument list function parameter. Returns false for last value (see Section creating user functions and modules).

function GetLocalString(name : string; defvalue : string) : string; - if TArtFormula compiled with multilang support, this function returns local value from current loaded language for string name and if string not set or empty it returns defvalue.

procedure LoadLang(lngfile : string); - if TArtFormula compiled with multilang support, this procedure load local strings from lngfile.

Events:

property GetVarsCount : TArtFormulaGetVarsCountProc;
TArtFormulaGetVarsCountProc = procedure(Vname:string; var count:integer; wantnumber:boolean=false) of object;
If you set ExternGetVars all unknown identifiers will treated as external variables. To evaluate them you should implement GetVarsCount and GetVarValue event handlers. GetVarsCount should return in count parameter number of values associated with Vname variable. Value of wantnumber specifies whether ArtFormula expects numerical values. GetVarsCount is called by ArtFormula when you pass external variable as a parameter of variant argument list function.

property GetVarValue : TArtFormulaGetVarProc;
TArtFormulaGetVarProc = procedure(Vname:string; n : integer; var Val:string; wantnumber:boolean=false) of object;
GetVarValue should return in Val parameter n-th value associated with Vname variable. n will change from 0 to count-1 where count returned by GetVarsCount event. Value of wantnumber specifies whether ArtFormula expects numerical values.

Note. Using GetVarsCount and GetVarValue you can implement for example range calculation in spreadsheet application when one parameter is passed in variant argument list function associated with number of cells.

Note. For fixed argument list function and when external variables are used as operands of expression, ArtFormula don't calls GetVarsCount and evaluates only first value associated with variable.

property OnLoadLang : TArtFormulaLoadLangProc;
TArtFormulaLoadLangProc = procedure of object;
If TArtFormula compiled with multilang support, this event arises when new local strings loaded from lng file. You can use this event to change local strings for installed TArtFormula modules or user functions.
----------------------------------------------
-
作者:
男 wr960204 (武稀松) ★☆☆☆☆ -
盒子活跃会员
2020/8/27 9:42:36
19楼: 实际上四则表达式计算是最简单的,一般数据结构和算法入门都有教的,就是对栈的操作而已。
这东西没啥成熟不成熟的。
----------------------------------------------
武稀松http://www.raysoftware.cn
作者:
男 luckyrandom (luckyrandom) ★☆☆☆☆ -
普通会员
2020/8/27 15:26:53
20楼: 类似表达式可能难以解决考勤的计算问题
偶之前开发考勤(工厂用,1万多人),涉及多班次、轮班,加班时长规则,请假、出差、节假日,补卡、漏卡等等规则,是用SP算的,SQL运算性能应该是最好的
----------------------------------------------
SQL SERVER DBA QQ:315054403 曾经的Delphier  缘在上海
作者:
男 hbug (hbug) ★☆☆☆☆ -
普通会员
2020/8/27 16:59:40
21楼: @luckyrandom 

1万多人的考勤记录,如果一次性计算,有没有记得要用多久才计算完?
----------------------------------------------
专业提供人力资源软件、指纹考勤软件、POS进销存软件、酒店餐饮软件
http://www.winsoftcn.com
作者:
男 hs_kill (lzl_17948876) ★☆☆☆☆ -
普通会员
2020/8/27 17:23:32
22楼: 呐, 我也贴个四则运算单元吧, 简单的
https://www.cnblogs.com/lzl_17948876/p/4923697.html

就是只支持几本四则运算及括号
----------------------------------------------
http://www.cnblogs.com/lzl_17948876/
作者:
男 lps (lps) ★☆☆☆☆ -
盒子活跃会员
2020/8/27 19:27:43
23楼: 以前做的表达式计算的测试程序,里面的sql部分是连接sql server的,其他数据库可以自行修改调试。
此帖子包含附件:lps_2020827192743.zip 大小:7.7K
----------------------------------------------
-
作者:
男 lps (lps) ★☆☆☆☆ -
盒子活跃会员
2020/8/27 19:30:57
24楼: 运行效果图
此帖子包含附件:
PNG 图像
大小:37.0K
----------------------------------------------
-
作者:
男 hbug (hbug) ★☆☆☆☆ -
普通会员
2020/8/28 8:14:43
25楼: @lps 感谢热心支持,给我提了一个新的思路。
----------------------------------------------
专业提供人力资源软件、指纹考勤软件、POS进销存软件、酒店餐饮软件
http://www.winsoftcn.com
作者:
男 kylix2008 (kylix2008) ★☆☆☆☆ -
普通会员
2020/8/28 16:07:44
26楼: ArtFormula功能强大,全源码(我的找不到了),支持众多的函数,还支持常量定义、变量、编程脚本(类pascal语法),觉得能满足常用需求。
记得最新版是2014年的V3.4,官网http://artsoft.nm.ru已经登不上了(是不是被墙了)?


这个免费公式计算器我常用,也很好用,我放电脑桌面常用来代替计算器了。官网 http://www.hjjok.com/ShowDownload/?4-1.html 已经下不了了,附件传一个。我以前用ArtFormula模仿这个公式计算器做了一个,嵌入我的软件中。
此帖子包含附件:kylix2008_2020828162911.rar 大小:2.54M
----------------------------------------------
-
作者:
男 hbug (hbug) ★☆☆☆☆ -
普通会员
2020/8/28 16:58:54
27楼: @kylix2008,我也是找了好久,没有找到,不然想试试这个。
----------------------------------------------
专业提供人力资源软件、指纹考勤软件、POS进销存软件、酒店餐饮软件
http://www.winsoftcn.com
作者:
男 hbug (hbug) ★☆☆☆☆ -
普通会员
2020/8/28 17:23:47
28楼: @kylix2008,试了一下你的计算器,if(1>0,'T','F') 类似这样的就不行,
 http://www.2ccc.com/article.asp?articleid=2370
这个解析可以正确返回 'T'的

包括嵌套 if(1>0,if(1=0,'y','n'),'F') ,能正确返回 'n'
----------------------------------------------
专业提供人力资源软件、指纹考勤软件、POS进销存软件、酒店餐饮软件
http://www.winsoftcn.com
作者:
男 lps (lps) ★☆☆☆☆ -
盒子活跃会员
2020/8/28 22:52:34
29楼: 楼主别瞎折腾了!你的问题只有一个解决方案,那就是存储过程,或者20楼说的SP
----------------------------------------------
-
作者:
男 dmzn (dmzn) ★☆☆☆☆ -
盒子活跃会员
2020/8/29 6:08:22
30楼: jcl > Source > Common > JclExprEval.pas
四则运算库.
----------------------------------------------
生活愉快.
作者:
男 minjiu (Bruce) ★☆☆☆☆ -
普通会员
2020/8/29 11:20:36
31楼: ArtFormula v.3.4 剛在某個站找到的,還沒試過,大家可以試試...
此帖子包含附件:minjiu_2020829112011.zip 大小:1.28M
----------------------------------------------
-
作者:
男 wiseinfo (wisienfo) ★☆☆☆☆ -
普通会员
2020/8/30 8:55:02
32楼: 在用QDAC的QMathExpr
----------------------------------------------
-
作者:
男 keymark (嬲) ▲▲▲△△ -
普通会员
2020/8/30 9:34:53
33楼: Documents\Embarcadero\Studio\20.0\Samples\Object Pascal\Database\FireDAC\Samples\Stan Layer\ExprEval

alcinoe\source\alcinoe\sourceALExprEval.pas
putersoft.sdk-filterbox\units\psc_expreval.pas
----------------------------------------------
[alias]  co = clone --recurse-submodules  up = submodule update --init --recursiveupd = pullinfo = statusrest = reset --hard懒鬼提速https://www.cctry.com/>http://qalculate.github.io/downloads.htmlhttps://www.cctry.com/
作者:
男 feiyanm (feiyanm) ▲▲▲▲▲ -
普通会员
2020/8/30 17:20:12
34楼: 我咋感觉这个问题也可以用MHS来解决呢?
http://www.moonserver.cn/mhs/download.pp
----------------------------------------------
Delphi威武!千秋万代,一统江湖!Delphi威武!千秋万代,一统江湖!Delphi威武!千秋万代,一统江湖!Delphi威武!千秋万代,一统江湖!Delphi威武!千秋万代,一统江湖!Delphi威武!千秋万代,一统江湖!Delphi威武!千秋万代,一统江湖!我去WC吐一会儿去!
作者:
男 hbug (hbug) ★☆☆☆☆ -
普通会员
2020/8/31 11:22:26
35楼: 谢谢大家。
QDAC官方网站是打不开了吧。
http://www.qdac.cc
----------------------------------------------
专业提供人力资源软件、指纹考勤软件、POS进销存软件、酒店餐饮软件
http://www.winsoftcn.com
作者:
男 sail2000 (小帆工作室) ★☆☆☆☆ -
盒子活跃会员
2020/9/1 18:30:27
36楼: TbcParser
修改一下即可跨平台
----------------------------------------------
delphi 是兴趣,和工作无关,即使它倒闭。又不靠它 delphi 吃饭,怕甚?
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行136.7188毫秒 RSS