Code highlighting

Thursday, February 23, 2012

Tip: Illegal 'closing bracket' character when defining a macro

Just a very quick tip today, related to macros:


As you all know, there are multiple ways to define and use macros in X++.
For those that need a refresher, please look up the corresponding section on MSDN
(Direct link: http://msdn.microsoft.com/en-us/library/cc197107.aspx)

Below is a simple X++ job, that demonstrates an existing shortcoming in the #define command, and a possible workaround for this problem.

Nothing complicated, basically, just use #localmacro, if you can't compile your code.

static void ClosingBracketInMacroDefinition(Args _args)
{
    //#define.Question("Why are brackets ')' not working ?")
    //#define.Question(@"Why are brackets ')' not working ?")
    //#define.Question("Why are brackets '\)' not working ?")
    #define.LegalCharacters(' !"#$%&\'(*+,-./:;<=>?@[\\]^_`{|}~\n\r\t')
    #localmacro.Question
        "Why are brackets ')' not working ?"
    #endmacro

    Box::info(#Question);
    Box::info(#LegalCharacters);
}

Thanks for finding the issue to Bogdana, one of our new developers.

2 comments:

  1. don't see the closing bracket in #define.LegalCharacters(' !"#$%&\'(*+,-./:;<=>?@[\\]^_`{|}~\n\r\t') ???

    ReplyDelete
  2. If you add it, it won't compile. So I specifically removed it.
    That's what the post is about :)
    Unless you define it as a localmacro.

    ReplyDelete

Please don't forget to leave your contact details if you expect a reply from me. Thank you