The issue with using multi-line macros in an *inc file, like your example, may arise from improper use of the ##continue directive required for breaking macros across multiple lines in InterSystems ObjectScript. The ##continue directive is used in macro definitions to indicate that the definition continues on the next line.
Here is how such a macro could be defined correctly:
#define ArrayToString(%array,%out,%del) ##continue
set %out="" ##continue
for { ##continue
set key=$order(%array("")) quit:key="" ##continue
set %out=%out_%del_key ##continue
} ##continue
quit
Key points to remember:
- The
##continuedirective must be at the end of every line that should be part of the macro, except the last line. - Indentation should not interfere, and the macro must be formatted correctly to avoid compiler errors.
In your macro, ##continue is missing at the ends of most lines, which prevents the compiler from understanding that the following lines are part of the same macro definition 12.
After correcting this, you can invoke the macro like this:
set tQStr = $$$ArrayToString(pQArray, tQStr, "##")
Ensure the *inc file containing this macro definition is included properly in your class or routine.
If compilation still fails, verify the expansion of your macro in the intermediate .INT code to identify syntax issues in the generated code. Debugging this can help reveal how the macro is being expanded and how corrections to the definition can resolve errors 21.
Sources:
- Log in to post comments