LoadModule

(Engine-Level Function)

Description: Loads a module from its .RUN files and returns a pointer to that module.
Returns: Module
Usage: Script Only.
Function Groups: Compilation and On-Line Modifications,  Advanced Module
Related to: Launch | Thread
Format: LoadModule(FileName, Library, [ModuleName, LoadNow, AppGUID, RefModule, TestCodeLoad])
Parameters:  
FileName  
Required. Any text expression giving the name of the .RUN file from which to load the module.
Library  
Required. Any module value that indicates the library module to which the loaded module will belong.
ModuleName
An optional parameter that is the text expression giving the module's name. This name will then be associated with the module when it is displayed in certain situations, such as in the debugger and the module tree diagram. If this parameter is invalid, the module will appear as "System" when its name is displayed.
LoadNow
An optional parameter that is any logical expression. If true (non-0), the module and its entire sub-tree are loaded immediately. If false (0), the module and its subtree are loaded on demand. The default is false.
AppGUID
An optional parameter that should be included and hold the text GUID of the application when the LoadModule is loading an application.
RefModule
An optional parameter that has been reserved for use by the Test Framework and is used when a module is being loaded in isolation of the application module tree.

Its presence allows source file offsets returned by the TextOffset statement to operate off the loaded module.
TestCodeLoad
An optional parameter that has been reserved for use by the Test Framework to indicate that the LoadModule is loading actual code to be run.
It can contain any Boolean expression that evaluates to TRUE to indicate that the code to run is being loaded.
Comments:

The return value is a pointer to the module. It can be used in a Launch or Thread statement.
The usage of the AppGUID and RefModule parameters determines how the VTScada engine will treat the module load:

  • If AppGUID and RefModule are both Invalid, this is a "normal" load. No special processing is performed.
  • If AppGUID is a text GUID and RefModule is absent or Invalid, the load is a load of the root module for the application. This causes the loading module to become the "namespace root" for the application.
  • If RefModule is valid, the loading module will cross-reference the reference module, enabling the TextOffset statement to return the correct source file offsets for the loading module. The RefModule must be part of the complete module tree for the application. It is also used to ensure that breakpoints are re-made when the test module reloads.

Example:

If ! Valid(CompiledModule);
[
   ExpressionTemplateRUN = RunFileName( FindVariable( "ExpressionTemplate", Self, 0, 0));
   CompiledModule = LoadModule( ExpressionTemplateRUN,  ExpressionParentModule, "Compiled Expression");
]