3
我使用ICompiledBinding
接口來判斷簡單的表達式,如果我用文字像(2*5)+10
工作正常,但是當我嘗試編譯像2*Pi
代碼失敗,出現錯誤:如何使用ICompiledBinding來評估包含`Pi`常量的表達式?
EEvaluatorError:Couldn't find Pi
這是我目前代碼
{$APPTYPE CONSOLE}
uses
System.Rtti,
System.Bindings.EvalProtocol,
System.Bindings.EvalSys,
System.Bindings.Evaluator,
System.SysUtils;
procedure Test;
Var
RootScope : IScope;
CompiledExpr : ICompiledBinding;
R : TValue;
begin
RootScope:= BasicOperators;
//Compile('(2*5)+10', RootScope); //works
CompiledExpr:= Compile('2*Pi', RootScope);//fails
R:=CompiledExpr.Evaluate(RootScope, nil, nil).GetValue;
if not R.IsEmpty then
Writeln(R.ToString);
end;
begin
try
Test;
except
on E:Exception do
Writeln(E.Classname, ':', E.Message);
end;
Writeln('Press Enter to exit');
Readln;
end.
所以我怎麼可以評估其中包含使用ICompiledBinding接口Pi
常量表達式?