saeedmandes
saeedmandes

Reputation:

Delphi, evaluate formula string

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.

Upvotes: 0

Views: 6597

Answers (5)

DmitryK
DmitryK

Reputation: 5582

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

https://www.mathparsers.com/formula-parser-for-delphi/

This component has source code included.

Upvotes: 4

Vegar
Vegar

Reputation: 12898

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

Upvotes: 5

John Thomas
John Thomas

Reputation: 4135

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.

Upvotes: 1

h0b0
h0b0

Reputation: 1869

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.

Upvotes: 0

smok1
smok1

Reputation: 2950

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

Upvotes: -1

Related Questions