Methods in X++
Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012
The following blocks of code are standard for X++ application classes:
Code block type
classDescription declaration block
Contains class modifiers such as public, private, and extends.
Also contains the field members for objects that are constructed from this class. IntelliSense can display a list of the members when you type the X++ keyword this.
The constructor. This method can be called only by using the new keyword. The syntax is typically similar to:
Derived classes can call the new method of their constructor by calling super method reference.
The destructor method.
However, in X++ this is a destructor only by convention. The finalize method is not called automatically by the system during garbage collection.
Additional methods for a class fall into the following types:
Methods can be created on many kinds of items in the AOT other than just classes. The list includes the following:
Instance methods, or object methods, are embedded in each object that is created from the class. They are called by using the following syntax:
You must instantiate the object before you can use the method.
If you later convert an instance method to a static method, you must restart the Microsoft Dynamics AX client for the compiler to note the change. Once you have converted the instance method to a static method, you can no longer call this method from the instance of the class -- only the class itself. Static methods are discussed in the next section.
Static methods, or class methods, belong to a class and are created by using the keyword static. They are called by using the following syntax:
You do not need to instantiate an object before you use static methods. Static methods are widely used in Microsoft Dynamics AX to work with data that is stored in tables.
It is not possible to use member variables in a static method.
For more information, see Static Methods.
A main method is a class method that is executed directly from a menu option.
static void main (Args _args)
// Your X++ code here.
The method should only create an instance of the object and then call the necessary member methods. The _args parameter allows you to transfer data to the method.
For more information, see Activating a class from a menu item.
Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.