Message directive

by Radek Červinka 20. December 2010 00:22

Sometimes is important to insert information to source code that displays during compilation. For this Delphi has $Message directive surprisingly with the parameters.

Syntax: {$MESSAGE HINT|WARN|ERROR|FATAL 'string' }

    1program Project1;
    2
    3{$APPTYPE CONSOLE}
    4
    5uses
    6  SysUtils;
    7
    8begin
    9  {$Message 'Information'}
   10  {$Message Hint 'Information message'}
   11  {$Message Warn 'Warning'}
   12  {$Message Error 'Error - compilation continues'}
   13  {$Message Fatal 'Total Error - stop compilation'}
   14{$IFNDEF KONF}
   15  {$Message Error 'Invalid configuration'}
   16{$ENDIF}
   17
   18end.

Output during compilation.

Checking project dependencies…
Compiling Project1.dproj (Debug, Win32)
dcc command line for "Project1.dpr"
[DCC Hint] Project1.dpr(9): H1054 Information
[DCC Hint] Project1.dpr(11): H1054 Information message
[DCC Warning] Project1.dpr(13): W1054 Warning
[DCC Error] Project1.dpr(15): E1054 Error - compilation continues
[DCC Fatal Error] Project1.dpr(17): F1054 Total Error - stop compilation
Failed
Elapsed time: 00:00:00.2

Line with Error is evaluated as error, but compilation continues. Line with Fatal stops compilation.

Tags:

Language

Comments are closed