So here is what I am trying to do:
I would like a parser that would evaluate equations and allow me to use custom functions. So, for example, an equation could be:
cos(5) * Patient:['lat1']
and it would let me have a function that does something if it finds Patient: in the expression.
The program I'm working on used a parser called MathParser (http://www.myart.bz/mathparser/), which worked fine in Delphi 2007, but has problems in Delphi XE (because of unicode). The MathParser site has a new version for XE, which I installed, but some functions have been changed around and I'm trying to get it to work right.
So, the problem seems to be with the custom function part, since everything else works fine.
The way I'm adding the functions is:
MathParser.AddFunction('Patient:', FPatFunction, fkMethod, FunctionMethod(PatFunction, 1),
False, False, vtDouble);
MathParser.AddFunction('Organ:', FOrgFunction, fkMethod, FunctionMethod(OrganFunction, 1),
False, False, vtDouble);
And then the functions themselves are
// patient function
function CEquatCalc.PatFunction(const AFunction: PFunction; const AType: PType;
const ParameterArray: TParameterArray): TValue;
begin
if Assigned(FPatient) and Assigned(FOrgan) then
AssignDouble(Result, (FPatient as CPatientItem).GetScoreVal((Trim(ParameterArray[0].Text)), (FOrgan as COrganItem)))
else if Assigned(FPatient) then
AssignDouble(Result,(FPatient as CPatientItem).GetScoreVal((Trim(ParameterArray[0].Text)), NIL));
end;
// organ function
function CEquatCalc.OrganFunction(const AFunction: PFunction; const AType: PType;
const ParameterArray: TParameterArray): TValue;
begin
AssignDouble(Result, (FOrgan as COrganItem).GetScoreVal((Trim(ParameterArray[0].Text))));
end;
The error that pops up says something like "Unknown element: lat1". Unfortunately since the component didn't come with Parser.pas (just the dcu file), I can't debug where it's happening.
Hopefully someone knows what the problem is, and if not, could you recommend another parser that would do what I want? (and is preferably free)