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 reacts on
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:
or
For notes:
For warnings:
{$Warning 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 $FatalError or $Stop messages is that when the
compiler encounters an error, it still continues to compile. With a fatal error, the compiler
stops.
Remark:You 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 the symbol RequiredVar
isn’t defined:
{$ifndef RequiredVar}
{$Error Requiredvar isn't defined !}
{$endif}
|
But the compiler will continue to compile. It will not, however, generate a unit file or a program
(since an error occurred).