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:
Where TYPE is one of
Alternatively, one of the following can be used:
Lastly, for fatal errors:
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 or stop, the compiler stops at once.
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 neither of the symbols RequiredVar1 or RequiredVar2 are defined:
But the compiler will continue to compile. It will not, however, generate a unit file or a program (since an error occurred).