计算就是基本的加减乘除及括号
如何实现?
3 个解决方案
#1
uses comobj;
var
m_Script: Variant;
begin
try
m_Script:= CreateOleObject('ScriptControl');
m_Script.Language := 'JavaScript';
showmessage( m_Script.Eval('0.6*0.8*2') );
except
showmessage( 'error' );
end;
end;
#2
uses comobj;
procedure TForm1.Button1Click(Sender: TObject);
var
m_Script: Variant;
begin
try
m_Script := CreateOleObject('ScriptControl');
m_Script.Language := 'JavaScript';
showmessage( m_Script.Eval('(4.3+0.3)*(3.25+0.3) ') );
except
showmessage( 'error' );
end;
end;
---------------------------
Project1
---------------------------
16.33
---------------------------
OK
---------------------------
#3
我试试看
#1
uses comobj;
var
m_Script: Variant;
begin
try
m_Script:= CreateOleObject('ScriptControl');
m_Script.Language := 'JavaScript';
showmessage( m_Script.Eval('0.6*0.8*2') );
except
showmessage( 'error' );
end;
end;
#2
uses comobj;
procedure TForm1.Button1Click(Sender: TObject);
var
m_Script: Variant;
begin
try
m_Script := CreateOleObject('ScriptControl');
m_Script.Language := 'JavaScript';
showmessage( m_Script.Eval('(4.3+0.3)*(3.25+0.3) ') );
except
showmessage( 'error' );
end;
end;
---------------------------
Project1
---------------------------
16.33
---------------------------
OK
---------------------------
#3
我试试看