{"id":4989,"date":"2019-01-12T14:20:29","date_gmt":"2019-01-12T06:20:29","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=4989"},"modified":"2019-03-06T09:52:33","modified_gmt":"2019-03-06T01:52:33","slug":"qmathexpr%e6%95%b0%e5%ad%a6%e8%a1%a8%e8%be%be%e5%bc%8f%e8%a7%a3%e6%9e%90%e5%92%8c%e6%89%a7%e8%a1%8c%e5%b7%a5%e5%85%b7","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=4989","title":{"rendered":"[QMathExpr]\u6570\u5b66\u8868\u8fbe\u5f0f\u89e3\u6790\u548c\u6267\u884c\u5de5\u5177"},"content":{"rendered":"\n<p>QMathExpr \u662f QDAC \u5bb6\u65cf\u7684\u4e00\u4e2a\u65b0\u6210\u5458\uff0c\u4e3a\u60a8\u63d0\u4f9b\u6570\u5b66\u8868\u8fbe\u5f0f\u7684\u89e3\u6790\u548c\u8ba1\u7b97\u529f\u80fd\u3002\u5b83\u652f\u6301\u4ee5\u4e0b\u7279\u6027\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u52a0\uff08+\uff09\u3001\u51cf\uff08-\uff09\u3001\u4e58\uff08*\uff09\u3001\u9664\uff08\/\uff09\u3001\u6c42\u4f59\uff08%\uff09\u8fd0\u7b97\uff0c\u9664\u6cd5\u65f6\u652f\u6301\u6574\u9664\u548c\u5e38\u89c4\u9664\u6cd5\u8fd0\u7b97\u3002\u7531\u4e8e % \u88ab\u7528\u505a\u6c42\u4f59\u8fd0\u7b97\u7b26\uff0c\u6240\u4ee5\u5982\u679c\u8981\u5f53\u505a\u767e\u5206\u53f7\u5904\u7406\uff0c\u8bf7\u5148\u76f4\u63a5\u5c06 % \u66ff\u6362\u4e3a \/100 \u5373\u53ef\uff0c\u5982 10*2% \u66ff\u6362\u6210 10*2\/100\uff0c\u7136\u540e\u518d\u89e3\u6790\u6267\u884c\u3002<\/li><li>\u6bd4\u8f83\u64cd\u4f5c\u7b26\u652f\u6301\uff08>\u3001>=\u3001=\u3001&lt;\u3001&lt;=\uff09<\/li><li>\u903b\u8f91\u975e\u652f\u6301\uff08!\uff09<\/li><li>\u652f\u6301\u5b57\u7b26\u4e32\u76f8\u52a0<\/li><li>\u5185\u7f6e 26 \u4e2a\u5e38\u89c4\u51fd\u6570\uff0c\u5305\u62ec\uff1a<ul><li>\u7edf\u8ba1\u51fd\u6570\uff1aMax(\u6700\u5927\u503c\uff09\u3001Min\uff08\u6700\u5c0f\u503c\uff09\u3001Avg\uff08\u5e73\u5747\u503c\uff09\u3001Sum\uff08\u6c42\u548c\uff09\u3001StdDev\uff08\u6807\u51c6\u65b9\u5dee\uff09 <\/li><li>\u4e09\u89d2\u51fd\u6570\uff1aSin\uff08\u6b63\u5f26\uff09\u3001Cos\uff08\u4f59\u5f26\uff09\u3001Tan\uff08\u6b63\u5207\uff09\u3001ASin(arcsin\uff0c\u53cd\u6b63\u5f26\uff09\u3001ACos(arccos\uff0c\u53cd\u4f59\u5f26\uff09\u3001ATan(arctan\uff0c\u53cd\u6b63\u5207),ATan2(arctan2\uff0c\u65b9\u4f4d )<\/li><li>\u51a5\u548c\u6307\u6570\u8fd0\u7b97\u51fd\u6570\uff1aPow\uff08\u5e42\uff09\u3001Ln\uff08\u81ea\u7136\u5bf9\u6570\uff09\u3001Log\uff08\u5bf9\u6570\uff09\u3001Sqrt\uff08\u5e73\u65b9\u6839\uff0c\u7b49\u4ef7\u4e8ePow(X,0.5)\uff09\u3001Exp\uff08\u7b49\u4ef7\u4e8ePow(E,x)\uff09<\/li><li>\u5176\u5b83\u51fd\u6570\uff1aRand\uff08\u968f\u673a\u6570\uff09\u3001IIF\uff08\u6761\u4ef6\u53d6\u503c\uff0c\u6761\u4ef6\u4e3a\u771f\u65f6\u53d6\u7b2c\u4e8c\u4e2a\u53c2\u6570\u7684\u503c\uff0c\u5426\u5219\u53d6\u7b2c\u4e09\u4e2a\u53c2\u6570\u503c\uff09\u3001ABS\uff08\u6c42\u7edd\u5bf9\u503c\uff09\u3001Trunc\uff08\u622a\u53d6\u6574\u6570\u90e8\u5206\uff09\u3001Frac\uff08\u622a\u53d6\u5c0f\u6570\u90e8\u5206\uff09\u3001Round\uff08\u56db\u820d\u4e94\u5165\uff09\u3001Ceil\uff08\u4e0a\u53d6\u6574\uff09\u3001Floor\uff08\u4e0b\u53d6\u6574\uff09\u3001Fact\uff08\u9636\u4e58\uff09<\/li><li>\u4e24\u4e2a\u5e38\u91cf\uff1aPI\uff08\u03c0\uff0c3.14159265358979\uff09\u548c\u81ea\u7136\u5bf9\u6570\u5e95\u6570e\uff082.71828182845905\uff09<\/li><\/ul><\/li><li>\u652f\u6301\u81ea\u5b9a\u4e49\u5e38\u91cf\u3001\u53d8\u91cf\u548c\u81ea\u5b9a\u4e49\u51fd\u6570\u652f\u6301\uff0c\u51fd\u6570\u53ef\u652f\u6301\u4e0d\u5b9a\u53c2\u6570<\/li><li>\u652f\u6301\u5c06\u7c7b\u578b\u4e8e 2sin(x) \u7684\u8868\u8fbe\u5f0f\u81ea\u52a8\u89e3\u6790\u4e3a 2*sin(x) \uff08\u6ce8\uff1a\u9700\u8981\u5f00\u542fNumIdentAsMultiply \u9009\u9879\uff09<\/li><li>\u652f\u6301\u8ba1\u7b97\u673a\u6574\u6570\u76f8\u9664\u89c4\u5219\uff0c\u5373 1\/2 \u7684\u7ed3\u679c\u4e3a 0 \u800c\u4e0d\u662f 0.5\uff08\u6ce8\uff1a\u9700\u5173\u95ed UseStdDiv \u9009\u9879\uff0c\u9ed8\u8ba4\u4e3a true\uff09<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u3010\u4f7f\u7528\u65b9\u6cd5\u3011<\/h4>\n\n\n\n<p>1\u3001\u521b\u5efa TMathExpression \u7684\u5b9e\u4f8b\uff0c\u60a8\u53ef\u4ee5\u5c06\u5b83\u8d4b\u7ed9 IMathExpression \u63a5\u53e3\uff0c\u4ee5\u51cf\u5c11\u9700\u8981\u81ea\u5df1\u91ca\u653e\u5bf9\u8c61\u7684\u9ebb\u70e6\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><\/p><cite> var<br>  AExpr:IMathExpression;<br>  AResult:Variant;<br>begin<br>    AExpr:=TMathExpression.Create;  <\/cite><\/blockquote>\n\n\n\n<p>2\u3001\u5982\u679c\u8868\u8fbe\u5f0f\u53ea\u8ba1\u7b97\u4e00\u6b21\uff0c\u90a3\u4e48\u76f4\u63a5\u8c03\u7528 Eval \u51fd\u6570\uff0c\u5c06\u8868\u8fbe\u5f0f\u4f20\u5165\u5373\u53ef\u3002\u4f46\u5982\u679c\u8868\u8fbe\u5f0f\u8981\u591a\u6b21\u91cd\u7528\uff0c\u5efa\u8bae\u5148\u8c03\u7528 Parse\uff0c\u7136\u540e\u518d\u591a\u6b21\u8c03\u7528 Eval \u6765\u8ba1\u7b97\u8868\u8fbe\u5f0f\u7684\u503c\uff0c\u4ee5\u51cf\u5c11\u89e3\u6790\u8868\u8fbe\u5f0f\u7684\u5f00\u9500\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u76f4\u63a5\u8c03\u7528\u793a\u4f8b\uff1a<\/li><li><\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><\/p><cite> AResult:=AExpr.Eval(&#8216;1+Max(2,3)&#8217;); <\/cite><\/blockquote>\n\n\n\n<ul class=\"wp-block-list\"><li>\u95f4\u63a5\u8c03\u7528\u793a\u4f8b<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><\/p><cite>AExpr.Parse(&#8216;1+Max(2,3)&#8217;);<br>AResult:=AExpr.Eval; <\/cite><\/blockquote>\n\n\n\n<p>3\u3001\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0cMax \u662f\u51fd\u6570\u3002\u8981\u589e\u52a0\u81ea\u5b9a\u4e49\u51fd\u6570\uff0c\u53ef\u4ee5\u8c03\u7528 Add \u6210\u5458\u51fd\u6570\u6765\u6dfb\u52a0\u3002Add \u51fd\u6570\u6709\u4e24\u4e2a\u91cd\u8f7d\uff1a<br><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><\/p><cite> function Add(const AVarName: String; AVolatile: TMathVolatile = mvVolatile)<br>       : TMathVar; overload;<br>function Add(const AFuncName: String; AMinParams, AMaxParams: Integer;<br>       ACallback: TMathValueEvent; AVolatile: TMathVolatile = mvVolatile)<br>       : TMathVar; overload; <\/cite><\/blockquote>\n\n\n\n<p>\u7b2c\u4e00\u4e2a\u91cd\u8f7d\u53ef\u4ee5\u8ba4\u4e3a\u662f\u7b2c\u4e8c\u4e2a\u91cd\u8f7d\u7684\u7b80\u5316\u7248\u672c\uff0c\u76f8\u5f53\u4e8e\u4e0d\u9700\u8981\u53c2\u6570\u7684\u5e38\u91cf\u3001\u53d8\u91cf\u6216\u51fd\u6570\u5b9a\u4e49\u3002\u6211\u4eec\u5f53\u7136\u4e5f\u53ef\u4ee5\u5728\u7b2c\u4e00\u4e2a\u91cd\u8f7d\u8fd4\u56de\u7684\u5bf9\u8c61\u91cc\u8bbe\u7f6e\u989d\u5916\u7684\u53c2\u6570\u63a7\u5236\u3002\u6211\u4eec\u8fd9\u91cc\u6f14\u793a\u4e0b\u5b83\u4eec\u7684\u7528\u6cd5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6dfb\u52a0\u4e00\u4e2a\u5e38\u91cf\uff0c\u6bd4\u5982\u6211\u4eec\u5b9a\u4e49 X \u4e3a\u4e00\u4e2a\u5e38\u91cf\uff0c\u503c\u4e3a100<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><\/p><cite> AExpr.Add(&#8216;X&#8217;,TMathVolatile.mvImmutable).Value:=100 <\/cite><\/blockquote>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6dfb\u52a0\u4e00\u4e2a\u53d8\u91cf\u6216\u51fd\u6570\uff0c\u5b9e\u9645\u4e0a\u5728 QMathExpr \u4e2d\uff0c\u53d8\u91cf\u88ab\u8ba4\u4e3a\u662f\u4e00\u4e2a\u65e0\u53c2\u6570\u7684\u51fd\u6570\uff0c\u6211\u4eec\u901a\u8fc7 TMathVar.OnGetValue \u4e8b\u4ef6\u6765\u83b7\u53d6\u5f53\u524d\u7684\u503c\u3002\u51fd\u6570\u7684\u7a33\u5b9a\u6027\u5728 QMathExpr \u4e2d\u5305\u542b\u4e09\u79cd\uff1amvImmutable\uff08\u5e38\u91cf\uff0c\u65e0\u8bba\u4ec0\u4e48\u65f6\u5019\u8c03\u7528\uff0c\u8fd4\u56de\u503c\u90fd\u662f\u56fa\u5b9a\u7684\uff09\u3001mvStable\uff08\u7a33\u5b9a\uff0c\u5728\u4e00\u6b21\u8ba1\u7b97\u4e2d\uff0c\u5176\u503c\u53ea\u83b7\u53d6\u4e00\u6b21\uff0c\u540e\u9762\u503c\u4e0d\u518d\u53d8\u5316\uff0c\u76f4\u5230\u4e0b\u4e00\u6b21\u8ba1\u7b97\uff09\u3001mvVolatile\uff08\u6613\u53d8\uff0c\u6bcf\u4e00\u4e2a\u5f15\u7528\u7684\u4f4d\u7f6e\u90fd\u9700\u8981\u5355\u72ec\u8ba1\u7b97\uff0c\u4e0d\u540c\u4f4d\u7f6e\u8fd4\u56de\u7684\u503c\u662f\u4e0d\u4e00\u6837\u7684\uff09\u3002\u5047\u8bbe\u4e3a\u6211\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570 List\uff0c\u8ba1\u7b97\u51fd\u6570\u7684\u6bcf\u4e2a\u53c2\u6570\uff0c\u5e76\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u7684\u503c\u3002<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><\/p><cite>procedure DoList(Sender: TObject; AExpr: TMathVar); <br>var<br>   I:Integer;<br>   AResult:Variant;<br>begin<br>for  I:=0 to High(AExpr.Params) do<br>   AResult:=AExpr.Params[I].Value;<br>AExpr.Value:=AResult;\/\/\u8bbe\u7f6e\u8fd4\u56de\u503c<br>end;<br>&#8230;.<br>AExpr.Add(&#8216;LIST&#8217;,1,MaxInt,DoList);\/\/\u6ce8\u518c\u51fd\u6570<br>&#8230; <br>AResult:=AExpr.Eval(&#8216;List(1,2,3)&#8217;);\/\/AResult=3<\/cite><\/blockquote>\n\n\n\n<p>\u5bf9\u4e8e\u51fd\u6570\u6765\u8bf4\uff0c\u5982\u679c\u53c2\u6570\u7684\u6570\u91cf\u662f\u56fa\u5b9a\u7684\uff0c\u5219\u5e94\u5c06\u6700\u5927\u53c2\u6570\u4e2a\u6570\uff08 AMaxParams \uff09 \u548c \uff08 AMinParams  \uff09\u503c\u8bbe\u7f6e\u4e3a\u540c\u4e00\u4e2a\u503c\u3002\u5982\u679c\u662f mvImmutable \u7c7b\u578b\u7684\u503c\uff0c\u8981\u6ce8\u518c\u6210\u5e38\u91cf\uff0c\u56e0\u4e3a\u53c2\u6570\u4e0d\u5f71\u54cd\u8fd4\u56de\u503c\u7684\u503c\uff0c\u6240\u4ee5\u5b83\u7684\u53c2\u6570\u4e2a\u6570\u6ca1\u6709\u610f\u4e49\uff0c\u53ef\u4ee5\u91c7\u7528\u7b2c\u4e00\u79cd\u6ce8\u518c\u65b9\u5f0f\u3002AMinParams \u7684\u503c\u9650\u5236\u4e86\u6700\u5c11\u7684\u53c2\u6570\u4e2a\u6570\uff0cAMaxParams \u9650\u5236\u4e86\u6700\u5927\u7684\u53c2\u6570\u4e2a\u6570\uff0c\u5982\u679c\u4e0d\u9650\u5236\uff0c\u90a3\u4e48\u8bf7\u5c06\u5176\u8bbe\u7f6e\u4e3a\u8db3\u591f\u5927\u7684\u6574\u6570\uff0c\u5982 MaxInt \u3002\u8fd9\u4e2a\u503c\u7684\u8bbe\u7f6e\u4f1a\u5728\u89e3\u6790\u8868\u8fbe\u5f0f\u65f6\u68c0\u67e5\uff0c\u6240\u4ee5\u5728\u8fdb\u5165\u6267\u884c\u9636\u6bb5\uff0c\u6211\u4eec\u53ef\u4ee5\u8ba4\u4e3a\u5b83\u7684\u4e2a\u6570\u662f\u7b26\u5408\u8981\u6c42\u7684\u3002<\/p>\n\n\n\n<p class=\"has-text-color has-background has-luminous-vivid-amber-color has-vivid-cyan-blue-background-color\">\u3010\u6ce8\u610f\u3011\u8bf7\u4e0d\u8981\u5728\u51fd\u6570\u4e2d\u4fee\u6539\u76f8\u5173\u53c2\u6570\u6570\u91cf\u548c\u503c\uff0c\u5b83\u7684\u884c\u4e3a\u5e76\u6ca1\u6709\u8fdb\u884c\u5b9a\u4e49\uff0c\u6240\u4ee5\u4ee3\u7801\u4e5f\u4e0d\u4fdd\u8bc1\u8fd9\u65b9\u9762\u7684\u903b\u8f91\u6b63\u786e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>QMathExpr \u662f QDAC \u5bb6\u65cf\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[69,8,9,766],"tags":[765,764,763,762,345],"class_list":["post-4989","post","type-post","status-publish","format-standard","hentry","category-c-builder","category-delphi","category-qdac","category-qmathexpr","tag-expression","tag-math","tag-763","tag-762","tag-345"],"views":4317,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4989","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4989"}],"version-history":[{"count":9,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4989\/revisions"}],"predecessor-version":[{"id":5015,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4989\/revisions\/5015"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}