Callbacks and Subscriptions

Several functions and library descriptions refer to callbacks, subscriptions, or both. The following definitions are offered for those who have not encountered these programming constructions before.

 

Callback

A callback is a reference to one module, passed to another. For example, you will see the following statement in every new script application:

  Window(  0,   0           { Upper left corner   },
         800, 600           { View area           },
         800, 600           { Virtual area        },
         Graphics()         { Start user graphics },
          {65432109876543210}
         0b00010000000110011,
         Concat(WinTitle, RunningOnVIC ? " - %S" : ""),
         0, 1);

Graphics() is a submodule of the application. When the Window function is called, it need to know what to display within its borders. That information comes from the parameter, Graphics(), which executes (calls-back) the display information. So long as the Window remains open (the enclosing state remains active) information coming back from Graphics() will continuously update.

Refer to the GridList function for further examples.

Sometimes, a callback module that you write will need to use objects within the caller. This is achieved using the CallBackScope syntax:

CallBackScope.SubModuleName();

Refer to examples in the GridList function where a callback for the grid titles calls the TitleClicked() submodule of the GridList to initiate the default action when a title is clicked.

 

Subscribe

Subscribing to something means that you want code to run whenever the value of that something changes. This is the essence of Steady State in VTScada, but there are situations where you need to explicitly state "do A when B" without using a script block triggered by an IF.