1.利用SQL的Exec()来计算
2.利用JavaScript来计算
3.利用逆波兰式来计算(比较复杂)
这里用JavaScript来实现
uses ComObj; function TForm1.DoCaculate(exp: string): string; var script: Variant; begin script := CreateOleObject('ScriptControl'); script.Language := 'JavaScript'; Result := script.Eval(Exp); end; procedure TForm1.btn1Click(Sender: TObject); var str:string; begin str:=DoCaculate('((1+2)*3)/3'); ShowMessage(str); end;