Tuesday, 22 May 2018

Macros & Const in AX7 / D365

Macros can still be created in Dynamics 365 for Finance and Operations to store a value that will not be modified.  They are created in either a macro file or by using the pound define keyword.  So we can see that here with our either hash tag or pound define.  

However, there is a new modifier to create constant variables.  By placing the keyword const before a variable, it will create the value that cannot be modified.

Const allows you to define members on a class and variables in a method that can only be initialized during the declaration. Constant value must be known at compile time. Compiler will replace references to these constants with the literal value.

Const also replaces most use cases of macros.

Example code:

Key Benefits:
IntelliSense in the editor.
- Support for "Go to definition" in the editor.
- Full control of the type for the constant.
- Faster compilation – macros are notorious hard for the compiler to handle.
- None of the macro idiosyncrasies – like the ability to redefine/override.

Reference link: X++ in AX7: Const keyword

No comments:

Post a Comment

Set up Online VM for Dynamics 365 Finance and Operation for Technical and Functional Learning Purposes

In this blog, I will discuss how we set up an online VM for D365F&O for Technical and Functional learning purposes for free. Step: 1 Cl...