TatScript Class
Represents a single script in the scripter component, holding source code, compiled p-code, and runtime state.
Remarks
TatScript object contains all information related to a script in the scripter component. The scripts are kept in the Scripts property which is a TatScripts collection. TatScript allows you to set the source code of the script using SourceCode property. Several methods are provided for clearing the script (Clear), compiling (Compile), executing (Execute). Information about the compiled script is also provided in the ScriptInfo property which holds the list of declared routines, global variables, etc. Many other properties and methods related to a single script are available.
Syntax
Unit: atScript
TatScript = class(TCollectionItem);
Methods
| Name | Description |
|---|---|
| AddObject | Registers the object AObject to be accessible from this script under the name AName. |
| Clear | Clears all compilation information for the script, resetting Compiled to False and removing associated events. |
| Compile | Compiles the current script source code. |
| EncodeSingleAssign | Override to provide the script-language-specific assignment expression for a single variable, used internally by debugger watches. |
| ExpandDebugInfo | ExpandDebugInfo is a deprecated method. It was used to update debug information in the compiled p-code of the script. Now this is done automatically and you don't need to call it anymore. |
| GetRowColFromSource | Converts a character position in the flat source string to its corresponding row and column values. |
| IsRegisteredAsLibrary | Use IsRegisteredAsLibrary to check if the script is registered as a script-based library in the scripter component specified by AScripter component. |
| LoadCodeFromFile | LoadCodeFromFile loads a compiled p-code from the file specified by AFileName. It calls LoadCodeFromStream internally to perform the loading operation. See LoadCodeFromStream method for more details. |
| LoadCodeFromStream | Loads a compiled script p-code from the stream specified by AStream. |
| LoadLibrary | Calls Scripter.LoadLibrary method. See TatCustomScriper.LoadLibrary method for more information. |
| RemoveObject | Removes an object previously registered with AddObject method. It can remove objects registered by TatCustomScripter.AddObject method. Those are global to all scripts and can't be individually removed from a specific script. |
| RuntimeError | Raises a runtime error with the specified message |
| SaveCodeToFile | Saves compiled p-code to the file specified by AFileName. Calls SaveCodeToStream internally.See SaveCodeToStream for more details. |
| SaveCodeToStream | Saves the compiled script p-code and meta-information to AStream. |
| SelfRegisterAsLibrary | Overloaded SelfRegisterAsLibrary(string) SelfRegisterAsLibrary(TatCustomScripter, string) |
| SelfUnregisterAsLibrary | Overloaded SelfUnregisterAsLibrary(string) SelfUnregisterAsLibrary(TatCustomScripter, string) |
| SilentCompile | Compiles the current script source code without raising an exception on error. |
| UnuseObject | Removes an object previously registered with UsesObject, identified by its class name. |
| UsesObject | Makes the methods and properties of the given object accessible directly from this script without using an object name. |
Properties
| Name | Description |
|---|---|
| Breaks | Provides access to the source-level breakpoint collection for this script. |
| Compiled | Indicates whether the script has been successfully compiled and is ready to execute. |
| DefInstances | Holds the list of default objects whose methods and properties are directly accessible from this script. |
| DesignFormResource | Gets or sets a form resource string used by the compiler instead of loading the DFM file, for IDE design-time use. |
| DesignScriptForm | Gets or sets a live form instance used by the compiler instead of loading the form file, for IDE design-time use. |
| ExpandedDebugInfo | ExpandedDebugInfo is true after ExpandDebugInfo method is called. This property is rarely used, since scripter expands the debug info automatically when needed. |
| FileName | If the script was loaded as a library from a file, contains the original file name where the script was loaded from. |
| FirstInstruction | FirstInstruction contains the pointer to the very first p-code instruction of the compiled script. The virtual machine uses this property to start executing the compiled p-code. You will not need to use this property. |
| IntInstance | IntInstance is the first object added automatically to the script using UsesObject. It's used internally by the scripter. |
| Parser | Provides access to the parser object that parses the script source code. |
| Refactor | Refactor property gives you access to the TatScriptRefactor object that allows refactoring operation in the script source code. See TatScriptRefactor for more information. |
| RefactorClass | RefactorClass property indicates which descendant of TatScriptRefactor will be used as Refactor object. Used only when creating descendants of TatScript. |
| Scripter | Use Scripter property to get access to the TatCustomScripter component that owns the script. |
| ScriptInfo | Provides access to the TatScriptInfo object containing meta-information about the compiled script. |
| SilentCompiled | Use SilentCompiled property to check if the script was compiled in silent mode (a call to SilentCompile method was performed). Setting SilentCompiled to true doesn't perform a silent compilation, it only sets the property value to true. |
| SourceCode | Gets or sets the script source code. Changing this property clears the compiled state. |
| UnitName | Gets or sets the unit name used to identify this script as a script-based library in uses clauses. |
| UsedUnits | Holds the collection of units declared in the script's uses clause. |
| VirtualMachine | VirtualMachine property provides access to the script virtual machine. The virtual machine is the object which effectively executes the compiled p-code. See TatVirtualMachine class for more info. |
| VirtualMachines | Not used, current version only allows one virtual machine per script. |
Events
| Name | Description |
|---|---|
| OnDestroy | OnDestroy event is fired when the script object is destroyed. |