JCL TEvaluator Usage

I am using the JCL TCompiledEvaluator (unit JclExprEval) but am having great difficulty trying to add a user function. I want to add a function of type TUnary32Func (1 parameter) but I cannot figure this out. Unfortunately, I cannot find any JCL documentation on this and the Google Ai assistant presents a number of conflicting and possibly bogus solutions.

The procedure call looks like this but I don’t know how to go any further successfully.

public procedure AddFunc(const AName: string; AFunc: TUnary32Func); overload;

Is there a working example anywhere?

Thanks, Gerard Hook

Hi Gerard

I don’t have an answer for you but have you considered DelphiWebScript.

Regards
Graeme

Thanks Graeme.

I will have a look.

Regards, Gerard Hook

Have a look at your $(BDSCatalogRepository)\JEDICodeLibraryJCL-13\2025.10\examples\common\expreval\ExprEvalExample.dproj, it gives use cases of
procedure TEasyEvaluator.AddFunc(const AName: string; AFunc: TUnary80Func);

Thanks Didier.

I see that the AddFunc calls are in the unit ExprEvalExampleLogic (from within the ExprEvalExample). It seems that the functions have to be stand alone and not a member of a class.

I got my test case to work.

Thanks again, Gerard Hook

Correct, most of the methods of that example are declared in the JclMath.pas unit.
But if you want to play with methods (ie class procedures /functions), then you could be using the Delphi new RTTI library: eg, for accessing the method → TRttiType.GetMethod, and for invoking it → TRttiMethod.Invoke.. unless you are stick with the JCL Expression Evaluator

To be more precise about your question that was:

You have to inspect what the AFunc: TUnary32Func parameter actually is.. It is defined as:
TUnary32Func = function(X: TFloat32): TFloat32;
..which means it is a function pointer, not a method pointer (or a method of an object’s instance), as you wanted it to be.
Note a method pointer would have been declared with the of object identifier.
See the Procedural Types DocWiki