Jump to content


Photo

TNxFormulaParser?


  • Please log in to reply
11 replies to this topic

#1 Thomas Steinmaurer

Thomas Steinmaurer
  • Members
  • 131 posts

Posted 08 October 2010 - 10:46 PM

Hello,

is there any documentation on the TNxFormulaParser component available?

Basically I'm trying to create a "rule builder" facility, which allows the user to visually define a boolean condition based on a set of named attributes (e.g. ExecutionTime, ...). The boolean condition/expression then needs to be evaluated with particular attribute values and getting True or False back for further actions.

I think TNxFormulaParser is made for that? If so, how to use it?

Thanks,
Thomas
Thomas Steinmaurer
LogManager Series - Logging/Auditing Suites supporting
InterBase, Firebird, Advantage Database, MS SQL Server and NexusDB V2
Upscene Productions: http://www.upscene.com
My blog: http://blog.upscene.com/thomas/

#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 08 October 2010 - 11:19 PM

Hello Thomas,

All you need is to set Expression property to some value, for example:

2+3+(2-1)
or
sum(2,3,4)

and then read RealResult property. (You may read abou functions that may be used on: http://dn.bergsoft.n...quick-start.htm (scroll down the page))

I hope that this can fit for your needs. I think that maybe you can pre-parse value that will be placed into Expression property. Maybe NxFormulaParser may be use as part of your engine.

You can also write:

22=22

and then read BoolResult. Maybe this is what you need?

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 Thomas Steinmaurer

Thomas Steinmaurer
  • Members
  • 131 posts

Posted 08 October 2010 - 11:34 PM

Hi!

my expression includes variable names, e.g. something like that:

ExecutionTime > 200

variable names then need to be replaced by its concrete value at run-time, so I need a way to access variables in an expression somehow. Is this possible?

Something like FieldByName or ParamByName from the Delphi database world comes to my mind.

Thanks,
Thomas
Thomas Steinmaurer
LogManager Series - Logging/Auditing Suites supporting
InterBase, Firebird, Advantage Database, MS SQL Server and NexusDB V2
Upscene Productions: http://www.upscene.com
My blog: http://blog.upscene.com/thomas/

#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 08 October 2010 - 11:42 PM

Hello Thomas,

I think that you will need to do pre-parse, to convert variable ExecutionTime to number. I think that you can do this with built-in delphi string functions.

Then, when you convert it to number - pass it to FormulaParser.

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 Thomas Steinmaurer

Thomas Steinmaurer
  • Members
  • 131 posts

Posted 08 October 2010 - 11:46 PM

Hi!

Ok. Thanks.

Btw, with Delphi 2010. Created a new VCL application. Dropped TNxFormulaParser onto the main form. Build the project. I get the following compiler error.

[DCC Fatal Error] F2092 Program or unit 'NxFormulaParser' recursively uses itself


Thomas


Thomas Steinmaurer
LogManager Series - Logging/Auditing Suites supporting
InterBase, Firebird, Advantage Database, MS SQL Server and NexusDB V2
Upscene Productions: http://www.upscene.com
My blog: http://blog.upscene.com/thomas/

#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 09 October 2010 - 12:01 AM

Hello Thomas,

This seems to be something wrong with Delphi. I have just tested it once again and all is well.

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#7 Thomas Steinmaurer

Thomas Steinmaurer
  • Members
  • 131 posts

Posted 09 October 2010 - 12:25 AM

Hmm. The same works in D2006 but not in D2010. As said. I very simple application with one form and TNxFormulaParser component. Never seen that before.

Thomas
Thomas Steinmaurer
LogManager Series - Logging/Auditing Suites supporting
InterBase, Firebird, Advantage Database, MS SQL Server and NexusDB V2
Upscene Productions: http://www.upscene.com
My blog: http://blog.upscene.com/thomas/

#8 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 09 October 2010 - 12:28 AM

Hello Thomas,

I just tested it in d2010 and all work fine.

It may be that there is a problem because component is loaded in 2 delphi IDE-s. Try to delete component from D2006 (better remove it from both IDE-s) and then install it clean on D2010.

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#9 Thomas Steinmaurer

Thomas Steinmaurer
  • Members
  • 131 posts

Posted 09 October 2010 - 12:37 AM

Guess what? I named my test project NxFormulaParser. ;-) Works now.

But, the component can't evaluate string constants, e.g.:

'a'='a'

gives False.


Thomas
Thomas Steinmaurer
LogManager Series - Logging/Auditing Suites supporting
InterBase, Firebird, Advantage Database, MS SQL Server and NexusDB V2
Upscene Productions: http://www.upscene.com
My blog: http://blog.upscene.com/thomas/

#10 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 09 October 2010 - 12:56 AM

Hello Thomas,

You may use:

strcomp('a','b')

Best regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#11 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 09 October 2010 - 12:57 AM

You will definitely need a pre-parser which will prepare expression from your program to expression for formulaparser
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#12 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 28 March 2011 - 11:59 PM

QUOTE (Thomas Steinmaurer @ Oct 9 2010, 12:34 AM) <{POST_SNAPBACK}>
Hi!

my expression includes variable names, e.g. something like that:

ExecutionTime > 200

variable names then need to be replaced by its concrete value at run-time, so I need a way to access variables in an expression somehow. Is this possible?

Something like FieldByName or ParamByName from the Delphi database world comes to my mind.

Thanks,
Thomas


Answering a bit late but the formulaparser allows you to register your own function and variables of certain types and the parser will evaluate them for you at runtime. No need for preprocessing. Have a look at:

CODE
procedure Addobject(adres : pointer; name  : string; typ   : Ftype);


and the declaration of Ftype. For your sample, call it like:

CODE
procedure Addobject(@ExecutionTime, 'ExecutionTime', tfp_intvar);


If you add a string variable the string is evaluated too.

G.W. van der Vegt




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users