Table of Contents

TatVirtualMachine Class

Executes the compiled p-code of an associated script and manages all runtime state during execution.

Remarks

After a script is compiled, the p-code is stored in memory and the script holds a reference to it. When the script is executed, the virtual machine processes the compiled p-code instruction by instruction. During execution, various internal variables are maintained. Especially during Delphi interoperation (accessing Delphi methods, properties, and variables), this runtime state is essential -- it provides the current object being accessed, the parameters passed to the current subroutine, and so on. This information is used by the method wrappers that implement Delphi interoperability.

Syntax

Unit: atScript

TatVirtualMachine = class(TCollectionItem);

Methods

Name Description
Clear Clear method resets the virtual machine, clearing several internal variables, erasing the stack, among other operations. You don't need to call Clear method, it's called internally by other methods of virtual machine.
CurrentMethodName Returns the name of the Delphi method being called by the virtual machine. This function is useful when you have a single wrapper for multiple Delphi method, this way you can tell which specific method is being called.
CurrentPropertyName Returns the name of the Delphi property being accessed by the virtual machine. This function is useful when you have a single wrapper for multiple Delphi properties, this way you can tell which specific property is being accessed.
DebugExecutionLine Returns the number of the next line in source code to be executed.
DebugRunToLine Unpauses the script (if paused) and continues script execution until the line specified by ALine is reached.
When that happens, the script execution is paused again.
DebugRunToPoint Unpauses the script (if paused) and continues script execution until the instruction specified by AInstruction is reached.
When that happens, the script execution is paused again.
DebugRunUntilReturn Unpauses the script (if paused) and continues script execution until current routine is terminated (or script main block).
DebugStepOver Performs debug step over operation in current script. This method should not be used very often because it works at p-code instruction level. Use DebugStepOverLine instead.
DebugStepOverLine Performs debug step over operation in script. A step over operation executes the current line and pauses the execution in the very next line. If the current line being executed is a routine call, the whole routine is executed at once.
DebugToggleBreakLine Creates a breakpoint (or removes it if one already exists) at the source line specified by ALine.
Returns the first p-code instruction that corresponds to that line.
DebugToggleBreak​Point Create a breakpoint (or remove if there is already one) in the instruction specified by AInstruction. This method returns true if a breakpoint was previously set, false otherwise. Do not use this method very often, use DebugToggleBreakLine instead.
DebugTraceInto Performs debug trace info operation in current script. This method should not be used very often because it works at p-code instruction level. Use DebugTraceIntoLine instead.
DebugTraceIntoLine Performs a debug trace-into operation in the script at source line granularity.
EntryPoint Returns the first p-code instruction of the routine specified by ALabel.
Execute Executes the script associated with this virtual machine, compiling it first if necessary.
ExecuteSubroutine Executes a specific routine declared in the script associated with this virtual machine.
GetArrayIndex Returns the index value of a Delphi indexed property being accessed by the virtual machine.
GetInputArg Returns the value of the parameter passed to the Delphi method currently being executed by the virtual machine.
GetInputArgAsBoolean Returns the value of the parameter passed to the Delphi method currently being executed, as a boolean value.
GetInputArgAsChar Returns the value of the parameter passed to the Delphi method being executed, as a char value.
See GetInputArg for more info.
GetInputArgAsClass Returns the value of the parameter passed to the Delphi method currently being executed, as a TClass reference.
GetInputArgAs​Date​Time Returns the value of the parameter passed to the Delphi method being executed, as a date time value.
See GetInputArg for more info.
GetInputArgAsFloat Returns the value of the parameter passed to the Delphi method being executed, as a float value.
See GetInputArg for more info.
GetInputArgAsInt64 Returns the value of the parameter passed to the Delphi method being executed, as an Int64 value.
See GetInputArg for more info.
GetInputArgAsInteger Returns the value of the parameter passed to the Delphi method being executed, as an integer value.
See GetInputArg for more info.
GetInputArgAsObject Returns the value of the parameter passed to the Delphi method being executed, as an object value.
See GetInputArg for more info.
GetInputArgAsString Returns the value of the parameter passed to the Delphi method currently being executed, as a string value.
GetInputArgAsUInt64 Returns the value of the parameter passed to the Delphi method being executed, as an UInt64 value.
See GetInputArg for more info.
GetInputArgAs​Wide​Char Returns the value of the parameter passed to the Delphi method being executed, as a wide char value.
See GetInputArg for more info.
GetInputArgAs​Wide​String Returns the value of the parameter passed to the Delphi method being executed, as a wide string value.
See GetInputArg for more info.
Halt Stops the current script execution. Same as setting Running property to false.
InProcessExecute Executes a script code fragment using the current virtual machine context.
InputArgCount Returns the number of arguments passed to the Delphi method currently being executed by the virtual machine.
InstructionByLine Returns the first p-code instruction that corresponds to the source code line specified by ARow.
ReturnOutputArg Sets the return value of the Delphi function currently being executed by the virtual machine.
ReturnOutputArgValue Same as ReturnOutputArg, but receives a TValue record instead a variant.
RuntimeError Raises a runtime error with the specified message
SetInputArg Sets the value of a by-reference parameter in the Delphi method currently being executed.
SetInputArgIfByRef Same as SetInputArg, with one difference: if the parameter is not passed by reference, nothing happens, while SetInputArg raises an exception. See SetInputArg for more information.
SetInputArgValue Same as SetInputArg, but receives a TValue record instead a variant.
SolveAbsolute​Addressing SolveAbsolute​Addressing method is used to translate address references to direct pointers, which are used by p-code jump instructions. You don't need to call this method, it's automatically called by the virtual machine when needed.

Properties

Name Description
BreakPoints Deprecated. Use TatScript.Breaks instead.
CallExecHookEvent Do not use this property, use TatCustomScripter.​Call​Exec​Hook​Event instead.
CurrentClass Returns the registered class whose class property or class method is currently being accessed or called by the virtual machine.
CurrentInstruction Returns the current p-code instruction being executed by the virtual machine.
CurrentObject Returns the Delphi object whose property or method is currently being accessed or called by the virtual machine.
DebugWatches Deprecated, do not use it. For watches manipulation, use TatScript.Watches instead.
Halted Returns true if the script has been halted and is still being executed. Halted property will always be false if the script is not running.
LastException​Class​Name Contains the class name of the last exception raised during script execution. For example, if the last exception raised was EConvertError, this function will return 'EConvertError'.
LastException​Help​Context Contains the help context of the last exception raised during script execution. Same as accessing HelpContext property of the exception object.
LastExceptionMessage Contains the error message of the last exception raised during script execution. Same as accessing Message property of the exception object.
NextInstruction Returns the next p-code instruction to be executed by the virtual machine.
Paused Indicates whether the current script execution is paused.
PrepareInstruction Returns a reference to the last p-code Prepare instruction executed by the virtual machine.
Running Use Running property to check if the current script is being executed (regardless of the value of Paused property). You can also set Running to true to execute a script, or set it to false to halt execution.
Script Returns the TatScript object which this virtual machine belongs to.
Scripter Returns the TatScripter component which this virtual machine belongs to.

Events

Name Description
OnDebugHook Do not use this event, use TatCustomScripter.​OnDebug​Hook instead.
OnExecHook Do not use this event, use TatCustomScripter.​OnExec​Hook instead.
OnPauseChanged OnPausedChanged is fired whenever the value of Paused property changes.
OnRunningChanged OnRunningChanged event is fired whenever the value of Running property changes.