数学、布尔表达式计算

 

 

相关资料:

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

 

posted on 2019-06-25 15:18  疯狂delphi  阅读(496)  评论(0编辑  收藏  举报

导航