Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

Application Server

Dynamically bind an indirect variable to a reference

Dynamically bind an indirect variable to a reference

  • Last UpdatedJul 22, 2024
  • 2 minute read

You can dynamically bind a variable of type Indirect to an arbitrary reference string and then use it for get/set purposes. For example:

' Assume reference obj1.Attr1 has value of 7

dim x as indirect;

dim s as string;

s = "obj1.Attr1";

x.BindTo(s); ' where s is any expression that returns a string.

' The string should be an ArchestrA reference.

obj2.Attr2 = x; ' sets obj2.Attr2 to the reference x is bound to

' (obj1.Attr1 in this example, which has value of 7)

x = 1234; ' sets obj1.Attr1 (in this example) to 1234

IF WriteStatus(x) == MxStatusOk THEN

' ... do something

endif;

Note: You can use .BindTo with an attribute on another engine, but this requires additional scripting of the bind to ensure good quality. For more information, see Bind to off-engine attributes.

An unbound indirect returns no data.

If the Galaxy has Advanced Communication Management enabled, we do not recommend that you use references that are part of an ActiveOnDemand DIObject scan group in a script with an Indirect. The reference activation process is not in sync with the script execution, so using a function such as the IsUseable() function always returns false.

For example, the following scripting is NOT recommended.

In the declarations section:

Dim pPump as Indirect;

In Script Body section

pPump.BindTo("Pump_001.State"); 'Pump_001 is part of a DIObject scan group that has ActiveOnDemand enabled

IF IsUsable(pPump)

THEN Do this….' this will not execute

ELSE

Do that…

ENDIF;

pPump.BindTo("Pump_002.State");'Pump_002 is part of a DIObject scan group that has ActiveOnDemand enabled

IF IsUsable(pPump)

THEN Do this….' this will not execute

ELSE

Do that…

ENDIF;

In the script, only Pump_002 is executing all of the time.

Important: If you have an existing application that uses the same Indirect variable with scripting more than one time for the items extended to device integration (DI) items or for DI items directly, and you enable Advanced Communication Management in the IDE, these scripts behave differently or do not execute as expected.

TitleResults for “How to create a CRG?”Also Available in