Macro-Operator / Runtim-Compiling

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Hi

in Clipper and VisualObjects is a Macro Operator available.
This opeartor evaluate Code stored in a String by the runtime-system.

e.g
....

cTest as string
cTest := "2+3"

? cTest // 2+3 type = String
? &cTest // 5 type = Numeric !

It is also possible to evaluate more complex code.
The Macro Operator has access to local (private) variable,
functions....
e.g.
...

function myFunc(i)
return i*10

......

declare a as float
declare b as float
declare n as float
declare c as string

a:=50
b:=3

c := "sin(a) + myFunc(b)"
n := &c // 30,766 ...


Error in the code (string) is handled by the error system: e.g

cTest := "2+3/0"
nResult := &cTest // --> error div. 0


Siply you can use the Operator to evaluate Input from User
whitout parsing the string by yourself.

I have to migrate an old Clipper Proggramm to dotnet. The Programm use
the Macro operator intensively to Calculate user defined reports.

I there a way to do this in cCharp ?

Thanks
Peter
 
I have to migrate an old Clipper Proggramm to dotnet. The Programm use
the Macro operator intensively to Calculate user defined reports.

I there a way to do this in cCharp ?

Not really.

JScript.NET has an Eval method(although I don't think it supports local
parameters) that you can use to execute JScript.NET code, but not C# code.

Your only other native option would be to use the C# compiler and compile
your code into an assembly and load it, but that will certainly not give you
access to locals. I think your best course of action would be to write or
find an interpreter for a script that is appropriate for your
project(perhaps XSLT with user defined functions would work?)
 
Back
Top