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

AVEVA™ Engineering

Communicating through Events and Delegate Call-backs

Communicating through Events and Delegate Call-backs

  • Last UpdatedJun 02, 2022
  • 2 minute read

The classic way to communicate between Graphical User Interface (GUI) controls (or the host module) and the code of applications while maintaining the object oriented principle of encapsulation is for the application to register call-backs functions as delegates to be called when certain events occur in the control or the module. In this way the specific code to deal with the application data resides in the application itself leaving the control or module independent of the application.

The AVEVA modules and standard GUI controls have a number of events built-in as standard. These are discussed elsewhere in this document:

  • Events discusses use of the built-in database events.

  • Add an Event to the Addin describes an example of using the NetGridControl and its standard events.

  • Command Events describes the standard events associated with a .NET Command object.

Users who build their own controls can also define their own system of events for communication with their application code. This is a standard part of the C# language, but the syntax is not straightforward. The following example illustrates the use of delegates and events.

Code in the control:

/// <summary>Event Handler definition for My Control</summary>

public delegate void MyControlEventHandler(ArrayList args);

/// <summary>After Data Filter is changed</summary>

public event MyControlEventHandler DataFilterChanged;

/// <summary>Another event ...</summary>

public event MyControlEventHandler AnotherEvent;

// ...

// Raise DataFilterChanged event

if (DataFilterChanged != null)

{

    ArrayList args = new ArrayList();

    // set args as required ...

    DataFilterChanged(args);

}

And in the application code:

// register a call-back function to handle Data Filter Changed events

myControl.DataFilterChanged +=

    new MyControlEventHandler (myControl_DataFilterChanged);

// ...

/// <summary>Handle the consequences of a changed data filter</summary>

private void myControl_DataFilterChanged(ArrayList args)

{

    // ...

}

And of course it is entirely possible for some or all of the application code to be implemented in Programmable Macro Language (PML). For this purpose the Common Application Framework (CAF) provides an event and call-back mechanism to communicate between C# and PML applications thus enabling effective encapsulation of behaviour in the code whichever combination of languages is chosen. Mixed language C#/PML working is covered in PML.NET.

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