Home > Back-end >  How [urgent] Delphi string (including variable) become available formulas?
How [urgent] Delphi string (including variable) become available formulas?

Time:10-22

Each master
Problem description:
There are three edit box, respectively: edit1, edit2, edit3,
A command button: for the,

1. Define a string variable: var s: a string;
2. Will the contents of the edit1 assigned to "s" variables, such as: s:=edit1. Text;
3. Input in edit2 formula such as "2 * s + 5"; (this formula is not the only, according to the need and decide)
4. Click for the formula to calculate the result of "s + 2 * 5" input to edit3. The text,

Such as: 3 in edit1 input, input in edit1 * 2 + 5 s, click for the, the output value in the edit3 "11",

CodePudding user response:

http://blog.csdn.net/simonhehe/article/details/8395610

CodePudding user response:

Can also be called JS eval ()

CodePudding user response:

USES the script control is Ok

CodePudding user response:

This is part of the compiler, arithmetic computation, the simple tell me about method, I do not know whether useful,

First cut token, cut the operators and operands, into a string list or array, it is not difficult,

Then do the parse () statement analysis processing, want to use recursive algorithm, the most simple, if you have braces, algorithm is a bit complicated, no brackets, only consider the operator precedence, algorithm is relatively simple, if you still want to simple, have to limit the input rule, forced to put the high priority operator in front, in this way, the parse process is just a few lines of code,

Operand if you include function, that is complicated, too serious to write compiler,

CodePudding user response:

refer to the second floor HSFZXJY response:
call JS eval () can also


The variables in the script to handle expression

CodePudding user response:

reference 1st floor simonhehe response:
http://blog.csdn.net/simonhehe/article/details/8395610


This can really realize variable function? I see introduction,

"Expression calculator, support four mixed operation, constants generation into the extended expression can realize nested references, prevent the functions such as circulation call
"
If support variables, and increase the square root calculation,

CodePudding user response:

If use the database, the formula to calculate directly to the database to calculate,

CodePudding user response:

refer to 6th floor crazywhh response:
reference 1st floor simonhehe response: http://blog.csdn.net/simonhehe/article/details/8395610

This can really realize variable function? I see introduction,

"Expression calculator, support four mixed operation, constant generation into the extended expression can realize nested references to prevent the functions such as circulation call"

If support variables, and increase the square root calculation,


The sample code in the PI is similar to your requirements of a s

Root, root, sine, cosine, etc need to be done in the process of formation of postfix expression rule, then when calculating the postfix expression processing respectively.
  • Related