表达式求值

利用VBScript的直接计算

unit Unit1;

interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,StrUtils, Spin,comobj;
type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);


  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}


function ExpCalc(exp: string): string;
var
  vScript: Variant;
begin
  vScript := CreateOleObject('ScriptControl');
  vScript.Language := 'VBScript';
  Result := vScript.Eval(exp);
end;




procedure TForm1.Button1Click(Sender: TObject);
var
  s:string;
begin
//  s:=edit1.text;
  s:=ExpCalc('100 *4.17/0.5*(55.22+22)/3.14');
  s:=ExpCalc(s);
  Edit2.Text := s;
end;


end.

你可能感兴趣的:(delphi开发)