The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,262 other subscribers

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.