首页 > 其他 > 详细

数学、布尔表达式计算

时间:2019-06-25 15:36:57      阅读:116      评论:0      收藏:0      [点我收藏+]

 技术分享图片

 

相关资料:

https://bbs.csdn.net/topics/390387168

 

注意:

uses
System.Win.ComObj;

 

实例代码:

技术分享图片
 1 unit Unit1;
 2 
 3 interface
 4 
 5 uses
 6   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
 7   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
 8 
 9 type
10   TForm1 = class(TForm)
11     Button1: TButton;
12     Edit1: TEdit;
13     Edit2: TEdit;
14     Label1: TLabel;
15     Label2: TLabel;
16     procedure Button1Click(Sender: TObject);
17   private
18     { Private declarations }
19   public
20     { Public declarations }
21   end;
22 
23 var
24   Form1: TForm1;
25 
26 implementation
27 uses
28   System.Win.ComObj;
29 {$R *.dfm}
30 
31 function ExpCalc(exp: string): string;
32 var
33   vScript: Variant;
34 begin
35   vScript := CreateOleObject(ScriptControl);
36   vScript.Language := VBScript;
37   Result := vScript.Eval(exp);
38 end;
39 
40 procedure TForm1.Button1Click(Sender: TObject);
41 var
42   s: string;
43 begin
44 //  s:=ExpCalc(‘100 *4.17/0.5*(55.22+22)/3.14‘); //20510.025477707
45 //  s:=ExpCalc(‘(true and true) or true and true‘); //true
46 //  s := ExpCalc(‘(false and true) or true and false‘); //false
47   s := ExpCalc(Edit1.Text);
48   Edit2.Text := s;
49 end;
50 
51 end.
View Code

 

数学、布尔表达式计算

原文:https://www.cnblogs.com/FKdelphi/p/11083026.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!