Promotic

Script directive #pragma of the PROMOTIC system

The #pragma script directive allows in the script to affect its usage in the PROMOTIC system and eventually also to modify the script content.
The #pragma directive is processed while the script is being translated which is the main difference compared to the calling the methods on the script launch. In case of the Web application, the scripts are running on the client side, but the #pragma directive processing is done on the server side and the client gets the processed script.
The PROMOTIC system processes the #pragma directive while translating the script and the corresponding code with the #pragma directive is then removed from the script. The original #pragma directive can be replaced by a new code, that can be a result of processing the corresponding #pragma directive.
Caution! The #pragma script directive is always placed in the script comment, i.e. in VBScript after the "apostrophe" character ('), in JavaScript after double "slash" characters (//).

There ar two types of #pragma directive:

#pragma variable

It is used for the modification of current script, it means that a new code, the result of corresponding #pragma directive evaluation, is inserted into the script.
This script directive inserts a code into the script, and in the script creates a local variable with corresponding name (by the statement var for JavaScript or Dim for VBScript) and then a code for variable initialization, that enters the desired value into the variable (the value can also be a reference to an object).
The inserted code created by evalueating the same #pragma directive in the same script may differ, for example, a local panel script compared to a Web panel script.
This type of #pragma directive makes the scripts more transparent, allows to systematically manage the object referrences and also allows to manage some differences between local and Web panels.

#pragma variable x = Macro("macro expression"):
It allows to evaluate the macro expression. It creates a local variable in the script and sets its original value to result of the macro expression evaluation. It is used especially for reading the localized text (Macro expression $.text). In the case of a Web application, the expression is evaluated on the server, therefore the #pragma directive evaluation can access the data and files of the servers.
For example '#pragma variable sComment = Macro("$.text('sys','comment')")
Another way to obtain the localized text is to use Macro expression $.text or EvalMacro.


#pragma variable x = PmaObjectRef("path"):
It allows to get the referrence to an Pma object in the Pma objects tree or its implementation subobject. It creates a local variable in the script and sets its original value to a referrence to desired object.
The reference to the object obtained this way is handy because it is known in the development environment PROMOTIC, it means that the PROMOTIC system knows about this reference and the type of the referred object, that will one day allow to add intelligent help in the script editor, listing the object methods, properties, etc.
For obtaining the object on a dynamic path (unknown in advance), serves the PmaObject.Pm method.
For example '#pragma variable oTemperature1 = PmaObjectRef("/Block1/Data/#vars/Temperature1")
For example '#pragma variable oTemperature1 = PmaObjectRef("../Data/#vars/Temperature1")


#pragma variable x = PmgObjectRef("path"):
It allows to get a referrence to a Pmg object or its implementation subobject in the panel. It creates a local variable in the script and sets its original value to a referrence to desired Pmg object or its implementation subobject This script directive is functional only in panel scripts (Pmg object events).
The reference to the object obtained this way is handy because it is known in the development environment PROMOTIC, it means that the PROMOTIC system knows about this reference and the type of the referred object, that will one day allow to add intelligent help in the script editor, listing the object methods, properties, etc.
For obtaining an Pmg object on a dynamic path (unknown in advance), serves the PmgObject.Items method.
For example '#pragma variable oEdit0 = PmgObjectRef("../edit0")
For example '#pragma variable oTemperature1 = PmgObjectRef("../edit0/#vars/Temperature1")

#pragma option

It is used for affecting the way the PROMOTIC system uses the script, it means that it sets some parameters of the PROMOTIC system. The script content is not modified (with the only exception of removing the #pragma directive itself).

#pragma option OldGlobalMethodCall:
It allows to switch on the old way of global method calling, where the global methods are colled in the script directly by its name (the same way as functions of the VBScript language). However this way is not compatible with Web applications. The new way requires to call the global methods by the Pm.Methods. This script directive is meaningful only for global methods of the application. If not set (or if the 0 value is used), then the new way of global method calling is used as default.
Syntax: '#pragma option OldGlobalMethodCall = 0/1
where 0 (default) is the ne way and 1 is the old way.

For example '#pragma option OldGlobalMethodCall = 1
An example of calling the Test global method with two parameters in the script directly by the old way:
  v = Test(5, 8)
An example of calling the Test global method with two parameters in the script directly by the new way:
  v = Pm.Methods.Test(5, 8)

History:
Pm8.03.07: Fixed bug: The #pragma option OldGlobalMethodCall script directive did not work in the script.
Pm8.00.00: When creating the scripts it is now possible to use so-called #pragma script directive. It is used for easier creation of instrumental variable, or for special signs for script interpretation.
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.