Macros

Macros are reusable components
Macros are mostly used to remove hardcoding and for constant values

Macros are pre-compiled
In AX, we have a macro processor

Macros cannot be debugged
Macros reduces line of code/optimizes the lines of code

Macros will not end with semicolon

Macros can be defined in 3 ways
1) Local Macro
2) AOT Macro
3) Macro library

1)Local macro is a mcaro which is local to that function and cannot be used outside the method/function

static void KAM_LocalMacro(Args _args)
{
    #define.pi(3.142)
    #define.name('Sreenath')
    #define.address('SR Nagar, Hyd')
    ;
   
    info(strfmt('%1',#pi));
    info(#name);
   
    info(#name + "is a bad person");
    info(#address);
}

2) AOT Macro

AOT Macros will help to resue the functions inside it.

Right click on the Macros node >> New Macro >> rename it to KAM

Add 4 functions inside the macros by doubling clicking it


#define.college('RV College')
#define.age(30)
#define.inst('Visual path')
#define.cl(4000.00)


How to call AOT Macro

Create a new job as shown below

static void kam_CallAOTMacro(Args _args)
{
    #KAM
    ;

    info(#college);
info(int2str#age));
}

How to use in any other object:

Go to KAM_CustTable >> initvalue() method and paste the following code

public void initValue()
{

    #kam
    ;

    super();
    this.Creditlimit = #cl;
    this.JoinedDate  = systemdateget();
}

3) Macro library:

Microsoft has already given many macros in AOT >> Macros node
[sys] layer

we can go ahead and add any function to already existing macros [sys layer]

AOT >> Macros >> AOTExport >> open in editor and add a new function at the end

#define.marks(30)
How to call Macro library macro

static void KAM_MacroLib(Args _args)
{
    #aotexport //#macrolib.aotexport
    ;

    info(int2str(#marks));
}


How to pass values or nuber of lines in Macros: possible

static void KAM_PassingValues_Macro(Args _args)
{
    int c;

    #localmacro.sum
    c = %1 + %2;
    #endmacro
    ;

    #sum(10,20)
    info(int2str(C));
   
    #sum(1000,5466)
    info(int2str(c));
}












Comments

Popular posts from this blog

Dynamics Ax 2012 Interview Questions:

Oops concept in AX