CHAPTER 1 - Introduction to X++
CHAPTER 2 - X++ Control Statements
CHAPTER 3 - Objects and Classes
CHAPTER 4: Accessing the Database
CHAPTER 5: Exception Handling
CHAPTER 6: Security for Developers
Lesson 8 – Method Types
Methods types in X++
There are many different types of method types in X++. Some of the more common types are discussed as follows.
- Static Methods: (The main method is a static method that can be used to call a constuctor. It is special because its name is required to be “main”. )
- Main Method: (The main method is a static method that can be used to call a constuctor. It is special because its name is required to be “main”. It is used by the system when the class is run directly from a menu item and it takes a parameter of type args)
- Display Methods: (Display methods are used on forms. They are commonly created on the table, and can also be defined on the form. Display methods return a value that is displayed on the form or report.)
- Accessor Methods: (Accessor methods enable other elements to set or get the values of variables in a class and it is common that they do both)
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: ClassName::methodName(); 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.
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.