Disabling events in scripts
Assigning a value to a field in a script brings the possibility of circular dependency, for example if there is an On-Change script for the field Trees["Attr'] defined as follows:
begin
Trees['Attr'] := Trees['Attr'] + 1;
Trees['Attr2'] := Trees['Attr'] + 10;
end.
Changing the value of the attribute Trees.Attr triggers the execution of this script, which changes the value of this attribute again - this in turn causes another execution of this script inside an already running script and so on. This would lead to an infinite depth of nested script execution and cause exhaustion of system resources. To avoid this situation, Field-Map scripting engine checks the nesting level of script execution and warns the user if it reaches a critical value suggesting a high probability of circular dependency. The user then can choose whether to continue the execution or not.
To control nested script execution and avoid the problem with circular dependency, there is a predefined integer variable named "DisableEvents". Setting this variable to a non-zero value causes that no action is taken when a line of code triggers execution of another script. Resetting this variable to 0 enables script execution again. Proper handling of this variable can solve all problems with circular dependency.
A modified example would look like this:
begin
DisableEvents := 1;
// We don't want to execute the On-Change event again,
Trees['Attr'] := Trees['Attr'] + 1;
DisableEvents := 0;
// but we want to run the Tree.Attr2 On-Change script, if any.
Trees['Attr2'] := Trees['Attr'] + 10;
end.
For disabling/enabling the activity of script as whole see DisableScripts and EnableScripts procedures. Property ScriptsEnabled serves to check the state of script enabling/disabling.
See also:
Accessing Field-Map data within a script; Using Field-Map predefined variables; Using Field-Map global variables; Disabling events; Referencing scripts
© 2024 IFER-Monitoring and Mapping Solutions