Promotic
WikipediaLinkedInYoutubeTwitterFacebook

Description of #pragma script directive in the PROMOTIC system

The #pragma directive allows the script to affect its usage in the PROMOTIC system and 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 directive is always placed in the script comment, i.e. in VBScript after the "apostrophe" character ('), in JavaScript after "double slash" character (//).

 
There ar two types of #pragma directive:
 

#pragma variable

It is used for the modification of current script, i.e. a new code, the result of corresponding #pragma directive evaluation, is inserted into the script. This directive inserts a code into the script, and creates a local script variable with corresponding name (by the Dim command) and then a code for variable initialization, that enters the desired value into the variable (the value can also be a referrence to an object). The inserted code created by evalueating the the same #pragma directive in the same script may differ, for example, a local panel script compared to a web panel script. This kind 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"):

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 localization text (Macro expression $.text). In case of a web application, the expression is evaluated on the server, therefore the #pragma directive can access the data and files of the servers.

For example '#pragma variable sComment = Macro("$.text('sys','comment')")

Another way to obtain the locatized text is to use Macro expression $.text or EvalMacro.

 
#pragma variable x = PmObjectRef("path"):

Allows to get the referrence to an Promotic object in object tree. It creates a local variable in the script and sets its original value to a referrence to desired object (for such variable, the Dim and Set commands are not used).

The referrence to the object obtained this way is handy, because it is known in the PROMOTIC development environment, i.e. the PROMOTIC system knows about this reference and the type of the referred object, that will one day allow to add intelligent help into the script editor, listing the object methods, properties, etc.

For obtaining the object on a dynamic path (unknown in advance), the PmObject.Pm method is used.

For example '#pragma variable oTemperature1 = PmObjectRef("/Block1/Data/#vars/Temperature1")

For example '#pragma variable oTemperature1 = PmObjectRef("../Data/#vars/Temperature1")

 
#pragma variable x = PmiItemRef("path"):

Allows to get a referrence to a graphic item 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 graphic item or its implementation subobject (for such variable, the Dim and Set commands are not used). This directive is functional only in panel scripts (graphic item events).

The referrence to the object obtained this way is handy, because it is known in the PROMOTIC development environment, i.e. the PROMOTIC system knows about this referrence and the type of the referred object, that will one day allow to add intelligent help into the script editor, listing the object methods, properties, etc.

For obtaining an item on a dynamic path (unknown in advance), the PmiItem.Items method is used.

For example '#pragma variable oEdit0 = PmiItemRef("../edit0")

For example '#pragma variable oTemperature1 = PmiItemRef("../edit0/#vars/Temperature1")

#pragma option

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

Allows to swith on the old way of global method calling, where the global methods are colled from the script directly by its name (the same way as the VBScript language functions). However this way is not compatible with web applications. The new way requires to call the global methods by the Pm.Methods. This directive is relevant only for global methods of the application. If not defined (or teh 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 from the script directly by the old way:

  v = Test(5, 8)

An example of calling the Test global method with two parameters from the script directly by the new way:

  v = Pm.Methods.Test(5, 8)

© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice