MESSAGE directive Delphi
Posted by jpluimers on 2021/03/09
I totally forgot to queue this, after putting in a draft in 2010. Luckily, nothing has changed since then: the [WayBack] MESSAGE directive Delphi which allows you to emit hint, warning, error (multiple) and fatal (single) messages to the Delphi from Delphi IDE “Messages” pane or to the command-line compiler output:
{$MESSAGE 'Boo!'} emits a hint {$Message Hint 'Feed the cats'} emits a hint {$messaGe Warn 'Looks like rain.'} emits a warning {$Message Error 'Not implemented'} emits an error, continues compiling {$Message Fatal 'Bang. Yer dead.'} emits an error, terminates compiler
You can use it like this to list a TODO, that might get more attention than a TODO comment in the code (earliest on-line documentation in Delphi 2007’s [WayBack] devcommon.pdf and [WayBack] Using To-Do Lists):
{$MESSAGE Hint 'TODO finish some work here'}
The most important thing to remember is do not forget the single quotes around the message.
Example from production code which tests for the permutations of defines related to [WayBack] FastMM4Options.inc
:
{$ifdef RELEASE} //... {$else} {$ifdef DEBUG} //... {$else} {$Message Error 'Unsupported FastMM4Options.inc build configuration: supported are RELEASE and DEBUG'} {$endif not DEBUG} {$endif not RELEASE} {$ifdef NoMessageBoxes} {$ifndef UseOutputDebugString} {$Message Error 'Unsupported combination: without NoMessageBoxes or UseOutputDebugString, no severe FastMM4 errors are emitted at all.'} {$endif not UseOutputDebugString} {$endif NoMessageBoxes}
–jeroen
Leave a comment