Recent

Author Topic: Using a string as actual code?  (Read 1584 times)

Kilian

  • Newbie
  • Posts: 4
Using a string as actual code?
« on: April 04, 2018, 06:28:20 pm »
Hello everyone,

i am working on a program right now, and i would like to be able to use a formula from the Text from a TEdit to calculate stuff.
So for example the user types: "x*x+5*x-4".
Then i want to say for example:
Code: Pascal  [Select][+][-]
  1. for x:= 1 to 10 do
  2.  begin
  3.   a:= TEdit.Text;
  4.  end;
But oviously i can't do that.
So is it possible to "convert" the string into "code", so that i can use the formula given by the user in my program, or are there other data types to accomplish that?

Thanks for any answers!
« Last Edit: April 04, 2018, 06:30:59 pm by Kilian »

CCRDude

  • Hero Member
  • *****
  • Posts: 600
Re: Using a string as actual code?
« Reply #1 on: April 04, 2018, 06:45:23 pm »
That would depend on your requirements. How about this?
http://wiki.freepascal.org/How_To_Use_TFPExpressionParser

If the string should contain more than math expressions, take a look at e.g. PascalScript:
http://www.remobjects.com/ps.aspx

Kilian

  • Newbie
  • Posts: 4
Re: Using a string as actual code?
« Reply #2 on: April 04, 2018, 08:10:15 pm »
@CCRDude Thanks, the ExpressionParser is working perfectly! Exactly what i looked for.

 

TinyPortal © 2005-2018