Free Pascal lets you define normal, warning and error messages in your code. Messages can be used to display useful information, such as copyright notices, a list of symbols that your code responds to etc.
Warnings can be used if you think some part of your code is still buggy, or if you think that a certain combination of symbols isn’t useful.
Error messages can be useful if you need a certain symbol to be defined, to warn that a certain variable isn’t defined, or when the compiler version isn’t suitable for your code.
The compiler treats these messages as if they were generated by the compiler. This means that if you haven’t turned on warning messages, the warning will not be displayed. Errors are always displayed, and the compiler stops if 50 errors have occurred. After a fatal error, the compiler stops at once.
For messages, the syntax is as follows:
{$Message TYPE Message text}
Where TYPE is one of
NOTE
a note message is emitted. Equivalent to $NOTE.
HINT
a hint message is emitted. Equivalent to $HINT.
WARNING
a warning message is emitted. Equivalent to $WARNING.
ERROR
an error message is emitted. Equivalent to $ERROR.
FATAL
a fatal error message is emitted. Equivalent to $FATAL.
Alternatively, one of the following can be used:
{$Info Message text}
For notes:
{$Note Message text}
For warnings:
{$Warning Warning Message text}
For hints:
{$Hint Warning Message text}
For errors:
{$Error Error Message text}
Lastly, for fatal errors:
{$Fatal Error Message text}
or
{$Stop Error Message text}
The difference between $Error and $Fatal or $Stop messages is that when the compiler encounters an error, it still continues to compile. With a fatal error or stop, the compiler stops at once.
RemarkYou cannot use the ’}’ character in your message, since this will be treated as the closing brace of the message.
As an example, the following piece of code will generate an error when neither of the symbols RequiredVar1 or RequiredVar2 are defined:
{$IFNDEF RequiredVar1} {$IFNDEF RequiredVar2} {$Error One of Requiredvar1 or Requiredvar2 must be defined} {$ENDIF} {$ENDIF}
But the compiler will continue to compile. It will not, however, generate a unit file or a program (since an error occurred).