Duplicate
I need a program in Delphi that get one variable equation from Edit1 such as "F(x)=4*X+2*log(x)+4*power(X,2)"
and get X value variable from Edit2 then show the result F(X) in Edit3. Please help me.
Thanks.
I need a program in Delphi that get one variable equation from Edit1 such as "F(x)=4*X+2*log(x)+4*power(X,2)"
and get X value variable from Edit2 then show the result F(X) in Edit3. Please help me.
Thanks.
It STRONGLY depdends on your decimal separator. Use StrToFloat or in newewr versions of Delphi - TryStrToFloat.
You probably need to have a look at this component - TbcParser.
http://www.bestcode.com/html/tbcparser.html
This component has source code included.
If you want to write an own implementation and not use a ready to use library this will take you some time to do. Just search for "formula parser". I would start with a tokenizer and then build a parse tree from the tokens.
Have a look at
http://www.efg2.com/Lab/Library/Delphi/MathFunctions/Parsers.htm
Also, if you have JEDI and/or FastReport libraries installed you can use their parsers. We use TParser10 from http://cc.embarcadero.com/item/15974 which is one of the fastest available if not the fastest. It is freeware and work flawlessly up to D2007. I heard that it works also in D2009. Not tested yet though.
You can also check out JCL, which comes with an expression evaluator in the file JclExprEval.pas. It's free and open source.