I noticed a strange behavior. If I create a function in one main unit, then Watch cannot evaluate it. But if I take it out to a new unit, then Watch normally returns the value of the function. What can be wrong?
Do you have a sample project reproducing the issue?
Yes, I have attached a test. When I press the first button "RUN (1 unit)", the Watch does not work. When on the second "RUN (2 units)" - everything is OK.
watch-example.zip (72.9 KB)
Indeed, in this case, you are trying to "execute" (via watch) a function that is in the same script that you are executing. This is not valid execution, and internally the watch evaluation fails.
In the second example, the function being executed is in a different script, and that works.
That is, it is impossible to use Watch for functions from the same script? For variables and constants, this works without issue.
Wagner, I hope you understand that this is not a solution. Fortunately, the user of the engine doesn't have to worry about the location of the function. Everything should work with any number of units. Do you plan to resolve this issue? Or at least tell me what to do in this situation?
Considering this post too:
Watches are not supposed to work with functions or any code execution. The fact that it works with a second unit is "luck". You should use watches with variables.
Got it, I give up) But one more question: what is the fastest way to calculate an expression (in Delphi) that can include any function, variable, constant? I was really hoping for Watch, but it didn't work.
I also try to use the method
TatVirtualMachine.InProcessExecute. Quote from the documentation:
/// <code> /// InProcessExecute('ShowMessage(MyVar);'); /// </code>
If I understand correctly, then this method can be called from anywhere in the program. But in the first case, as with Watch, we get an exception. I am attaching a test and a screenshot of the program.
example-InProcessExecute.zip (84.2 KB)
In general, my task is extremely simple: to evaluate the expression at any moment of the program execution. This expression can includes variables, constants, functions from any program unit.
You can use
ExecuteRoutine to execute a specific routine, but not when a script is already being executed.
There is no current way to execute code while the scripter is executing. It's not stable, scripter is not prepared for that, that's why watches can't do that, as I mentioned already.
Wagner, I'm sorry for my questions and I'm wasting your time. I found a solution that works great (for now).
As you said, only variables are adequately calculated in Watch. So I proceed like this:
- Add global "service" variable
V: Variantto the script.
- Where needed, on-the-fly create a debug script (one simple unit).
- In the debug script write
Expressioncan include variables, constants, functions. This is a common expression in Pascal.
- Call Watch for variable
- Delete debug script.