Hi There!
The new component TFPMathExpressionBridge is a warapper for the math subset
of TFPExpressionParse (fpexprpars.pas) attempting to establish a intuitive semantics
for construction of function graph and expression evaluete.
More specifically the underline code used here is a WP revision and addOns. (Thank you WP!)
Attached content:
1. tfpmathexpressionbridge_lazarus_package - Component install
2. tfpmathexpressionbridge_demo1 - TAChart FuncSeries example
3. tfpmathexpressionbridge_demo2 - TAChart ParametricCurveSeries example (need r40137)
About TFPExpressionParser and Wp addOns follow there

App Demo 2 use "TParametricCurveSeries" added to unit "tafuncseries.pas" on TAChart revision 40137
http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/components/tachart/tafuncseries.pas?annotate=40137&root=lazarus&pathrev=40137about TAChart TParametricCurveSeries follow this:
http://www.lazarus.freepascal.org/index.php/topic,19627.msg111853.html#msg111853The TFPMathExpressionBridge "readme.txt":
TFPMathExpressionBridge - Version 0.1 - 02/2013
Author: Jose Marques Pessoa : jmpessoa__hotmail_com
Acknowledgment: Thank you WP!
TFPMathExpressionBridge is a warapper for [math]* subset
of TFPExpressionParse** attempting to establish a easy semantics
for construction of function graph and expression evaluete.
0. Warning: at the moment this code is just a "proof-of-concept".
1.Data
1.1 Add Data
Add Constants
Add Variables
Add Expressions
use:
AddConstant('k')
AddVariable('x')
AddExpression('kx+1')
Obs.: Data are Case Insensitive!
1.2 Set Data
Set Expression //triggers OnConstantParse...
use: Expression:= 'k*x+1'
or by Helpers:
procedure SetExpressionByIndex(Index: integer);
function GetExpressionByIndex(Index: integer): string;
function GetExpressionIndexByName(AName: string): integer;
Set VariableOfFunc //variable of "functions of one variable"
use: VariableOfFunc:= 'x'
2.Evaluete
2.1 Function Evaluete
function EvalFunc(AValue: real) //eval function for one variable....
use: EvalFunc(AValue)
function EvalFunc(AValues: array of real) //eval function for many variables...
use:EvalFunc([AValue1, AValue2, AValue3])
2.2 Expression Evaluete //event driver
function EvalExpr(Expr: string; ANamesVar: array of string)
use: EvalExpr('A*x**x+ B*x + C', ['x','A','B','C']) //triggers OnVariableParse
function EvalExpr
use:
AddConstant('A')
AddConstant('B')
AddConstant('C')
AddVariable('x')
Expression:= 'A*x**x+ B*x + k*C'
EvalExpr; //triggers OnVariableParse
3. Events
3.1 OnConstantParse //triggers every time Expression is Set.....
use: handle to set constant value
3.2 OnVariableParse //triggers every time EvalExpr is called.....
use: handle to set variable value
4.Add "building" function
//signature:
type
TExprFunc = procedure(Var Result: TFPExpressionResult; Const Args: TExprParameterArray);
//"building" funtion code example:
Procedure ExprDelta(Var Result: TFPExpressionResult; Const Args: TExprParameterArray);
var
a,b,c: Double;
begin
a := ArgToFloat(Args[0]);
b := ArgToFloat(Args[1]);
c := ArgToFloat(Args[2]);
if IsNumber(a) and IsNumber(b) and IsNumber(c) then
Result.resFloat := b*b - 4*a*c
else
result.resFloat := NaN;
end;
4.1 AddFunction(AName: string; paramCount: integer; callFunc: TExprFunc)
Use:
AddFunction('Delta', 3, @ExprDelta);
Use:
Expression:='Delta(2,4,1)';
EvalExpr;
5. Have Fun!