You can use Live Bindings to evaluate expressions. Here's a trivial example:
program BindingsDemo;
{$APPTYPE CONSOLE}
uses
System.Rtti,
System.Bindings.Expression,
System.Bindings.EvalProtocol,
System.Bindings.Helper;
type
TFoo = class
Val1: Integer;
Val2: Integer;
Result: TValue;
end;
procedure Main;
var
Foo: TFoo;
scope: IScope;
expr: TBindingExpression;
begin
Foo := TFoo.Create;
Foo.Val1 := 42;
Foo.Val2 := 666;
scope := TBindings.CreateAssociationScope([Associate(Foo, 'Foo')]);
expr := TBindings.CreateUnmanagedBinding(
[Scope],
'Foo.Val1 + Foo.Val2',
[Scope],
'Foo.Result',
nil
);
expr.Evaluate;
Assert(Foo.Result.AsInteger=708);
Writeln(Foo.Result.ToString);
end;
begin
Main;
Readln;
end.
Note, I've intentionally omitted the code to free objects and so this code leaks. I chose to do that so we could concentrate on the expression evaluation aspect.