views:

523

answers:

5

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.

A: 

It STRONGLY depdends on your decimal separator. Use StrToFloat or in newewr versions of Delphi - TryStrToFloat.

smok1
+4  A: 

You probably need to have a look at this component - TbcParser.

http://www.bestcode.com/html/tbcparser.html

This component has source code included.

DmitryK
A: 

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.

h0b0
+1  A: 

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.

I'm the author of one of the packages on that list, Symbolic.Note that the URL there goes to the original (FPC) package. The Delphi package is at http://www.stack.nl/~marcov/symbolicdelphi.zip
Marco van de Voort
+2  A: 

You can also check out JCL, which comes with an expression evaluator in the file JclExprEval.pas. It's free and open source.

Vegar