Export (0) Print
Expand All

Event Terminology and Keywords [AX 2012]

Updated: February 25, 2010

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

In Microsoft Dynamics AX, you can use the event design pattern to make your X++ code more modular and reusable. The term event is a metaphor that explains how delegates are used.

When something important occurs during a program run, there might be other modules that need to process the occurrence. These important occurrences are called events. When an event occurs, the program tells its notifier for the event that the notifier must send notifications of the event. A notification must be sent to all the event handlers that are subscribers of the notifier. When the program tells its notifier to send the notifications, we call that raising an event.

The following table displays the terms that are used to describe the event metaphor.

Metaphorical term

Description

event

An important occurrence in a program module where additional modules must process the occurrence.

notifier

The program element that sends information about the event to all the event handlers that are subscribed to the notifier.

subscriber

The program functions or methods that are subscribed to an event notifier.

event handler

The methods that subscribe to an event notifier. Only the appropriate kind of methods can be event handlers.

The event design pattern starts when you use the AOT > Classes > MyClass > New > Delegate menu to add a delegate to a class.

The following table shows the X++ keywords that describe the use of delegates in X++.

X++ keyword or term

Code

Description

delegate

delegate myDelegate(str _information) {}

The code shows how the delegate looks in the method editor in the MorphX client. The return type is always void, so it is not mentioned in the syntax. No code is allowed inside the {} braces.

eventHandler

myClassInstance.myDelegate += eventHandler(otherClass.myInstanceMethod);

The syntax of the eventHandler keyword might give the impression that eventHandler is an X++ function, but it is not a function. The eventHandler keyword tells the compiler that a method is being subscribed to a delegate.

Subscribe or add a method to a delegate

myClassInstance.myDelegate += eventHandler(OtherClass::aStaticMethod);

The static method OtherClass::aStaticMethod becomes subscribed to the delegate.

Call a delegate

myClassInstance.myDelegate("Hello");

This call to the delegate prompts the delegate to call each method that is subscribed to the delegate. The subscribed methods are called in the same sequence in which they were added to the delegate. One subscribed method must complete before the delegate calls the next method.


Announcements: To see known issues and recent fixes, use Issue search in Microsoft Dynamics Lifecycle Services (LCS).

Community Additions

ADD
Show:
© 2014 Microsoft