Macros in axapta

In Axapta’s predecessor, macros were widely used. The predecessor did not support
classes, so macros were used instead. This might be the reason that macros are a part of
MorphX today. In MorphX macros are not commonly used. A few places make use of
macros such as keeping track of the list of fields stored when using dialogs. It is
recommended only to use macros to define constants. Macros are not supposed to be
used for code, as reusing code from macros is not flexible as using methods.
Macros can be created under the Macro node in the AOT, as a local macro in a method
or a single line defining a constant. The main difference between a macro and a method
is that a macro has no variable declaration part, and the code in a macro is not validated
for errors before executed from a method. This is one of the main reasons not to put
code in macros, as it makes the code more difficult to read.


When using macros in your code, the macros must be declared after the variable
declaration. The common place to put the definition is in the ClassDeclaration of a
class, form or a report. This will make the macro definition available for all parts of the
object.
Macro commands
For writing macros a set of simple macro commands are used. You have commands for
setting the start and the end of a macro like in a method. An if-statement can be set to
control the flow of a macro. Macro if statements are used to validate whether a
parameter is specified for a macro or not. For a list of the macro commands.


#define
Used to define a constant.
See macro HRMConstants.
Example

#define.myConstant100(’100′)

#endif
Ends a #if.empty or a #if.notempty statement.

#endmacro
Ends a #LOCALMACRO or a #GLOBALMACRO.
#globalmacro
No difference whether declaring the start of a macro with #localmacro or

#globalmacro. #globalmacro is not used in the standard package, consider using
#localmacro instead.

#if.empty
Will return true if the macro has not been called with the parameter validated in the
statement.
Example
#if.empty(%3)
%3 = %2;
#endif

#if.notempty
Will return true if the macro has been called with the parameter validated in the
statement.
See macro InventDimJoin.
Example
#if.notempty(%3)
print %3;
#endif

#linenumber
Returns the current line number of the macro. Can be used while debugging, but not
of must use.

#localmacro
Specify the start of a local macro. See classDeclaration for class
SalesReport_Heading.
Example
#localmacro.MyLocalMacro
print %1;
#endmacro

#macrolib
Used to load an AOT macro from code. See class method
BOMHierarchy.searchDownBOM().
Example
#macrolib.MyMacro

Source Steen Andreasen’s book

MORPHX IT
An introduction to Axapta X++
and the MorphX Development Suite

 
Comment are closed.