next up previous contents
Next: Macros Up: Using conditionalsMessages and Previous: Conditionals

Messages

  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. In general anything which may cause problems when compiling.

Error messages can be useful if you need a certain symbol to be defined to warn that a certain variable isn't defined or so, 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 e displayed. Errors are always displayed, and the compiler stops as if an error had occurred.

For messages, the syntax is as follows :

{$Message Message text }
Or
{$Info Message text }
For notes:
{$Note Message text }
For warnings:
{$Warning Warning Message text }
For errors :
{$Error  Error Message text }
Lastly, for fatal errors :
{$FatalError  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).



Michael Van Canneyt
Thu Sep 10 14:04:11 CEST 1998