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:

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')
        "Why are brackets ')' not working ?"


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


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

  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.


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