Sign in Join
Wiki copytemporary

Turn warnings and hints on or off: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-There are several ways to control the behavior of warnings in both the Lazarus IDE and in the source code itself. Some warnings and hints are not very useful in a particular case so you want to hide them from view. On the other hand, if you would hide warnings or hints globally, you may want to turn a particular warning or hint explicitly on for a particular piece of your code.
2-
3-``` pascal
1+There are several ways to control the behavior of warnings in both the Lazarus IDE and in the source code itself. Some warnings and hints are not very useful in a particular case so you want to hide them from view. On the other hand, if you would hide warnings or hints globally, you may want to turn a particular warning or hint explicitly on for a particular piece of your code.
2+```
43procedure TForm.Button1Click(sender:Tobject);
5-begin
6- // Do something that does not use sender
7- Form1.Button1.Caption := 'Test';
8-end;
4+ begin
5+ // Do something that does not use sender
6+ Form1.Button1.Caption := 'Test';
7+ end;
98```
109
11-This will generate a hint that parameter sender is not used. Doh. I can see that! Problem is that this hint turns up all over the place and I know what it means. How do I hide them?
10+This will generate a hint that parameter sender is not used. Doh. I can see that! Problem is that this hint turns up all over the place and I know what it means. How do I hide them?
1211
1312# Lazarus IDE options
1413
15-The Lazarus IDE can control hints and warnings in two ways:
14+The Lazarus IDE can control hints and warnings in two ways:
1615
17-- Globally through the Project Options menu
18-- Using an IDE macro
16+ * Globally through the Project Options menu
17+ * Using an IDE macro
1918
2019## Global IDE option
2120
22-Go to the Project Options-\>Compiler Options-\>Messages and uncheck 'Hint:Paramater "\$1" not used'.
21+Go to the Project Options->Compiler Options->Messages and uncheck 'Hint:Paramater "$1" not used'.
2322
24-This will turn of this particular hint for your whole project.\
25-If you would like to turn off this hint for all your projects, you can check the left bottom checkbox 'Set compiler options as default'.
23+This will turn of this particular hint for your whole project.
24+If you would like to turn off this hint for all your projects, you can check the left bottom checkbox 'Set compiler options as default'.
2625
27-![](/wiki-images/e/e3/Lazarusglobal.png)
26+[![lazarusglobal.png](/wiki-images/d/da/lazarusglobal.png)](</File:lazarusglobal.png>)
2827
2928## Local IDE option
3029
31-In the Lazarus IDE you can make use of the {%H-} IDE macro to turn hints off for a particular parameter.\
32-Of course {%H+} will turn hints on.
33-
34-``` pascal
35- procedure FormMouseDown(Sender: TObject; {%H-}Button: TMouseButton;
36- {%H-}Shift: TShiftState; {%H-}X, {%H-}Y: Integer);
30+In the Lazarus IDE you can make use of the {%H-} IDE macro to turn hints off for a particular parameter.
31+Of course {%H+} will turn hints on.
3732```
33+procedure FormMouseDown(Sender: TObject; {%H-}Button: TMouseButton;
34+ {%H-}Shift: TShiftState; {%H-}X, {%H-}Y: Integer);
35+```
3836
39-Note that this turns off ALL hints for that parameter, not just the 'is not used' hint, so be careful.
37+Note that this turns off ALL hints for that parameter, not just the 'is not used' hint, so be careful.
4038
4139# Source code and compiler options
4240
43-The options as described above will only work within the Lazarus IDE.
41+The options as described above will only work within the Lazarus IDE.
4442
45-It won't work in any other IDE, not even de FPC textmode IDE. The compiler output will still emit warnings and hints.
43+It won't work in any other IDE, not even de FPC textmode IDE. The compiler output will still emit warnings and hints.
4644
47-Luckily there are several other options to control hints and warnings in the source code itself.
45+Luckily there are several other options to control hints and warnings in the source code itself.
4846
4947## Control all warnings per unit:
5048
51-Add
52-
53-``` pascal
49+Add
50+```
5451{$warnings off}
5552```
5653
57-or resp.
58-
59-``` pascal
54+or resp.
55+```
6056{$warnings on}
6157```
6258
63-just after the unit name.
59+just after the unit name.
6460
6561## Control all hints per unit:
6662
67-Add
68-
69-``` pascal
63+Add
64+```
7065{$hints off}
7166```
7267
73-or resp.
74-
75-``` pascal
68+or resp.
69+```
7670{$hints on}
7771```
7872
79-just after the unit name.
73+just after the unit name.
8074
8175## Control specific warnings:
8276
83-Add
84-
85-``` pascal
77+Add
78+```
8679{$warn <number> off}
8780```
8881
89-just after the unit name. See the example below. You can also use this construct if you want all warnings off but some specific warning(s) on:
90-
91-``` pascal
82+just after the unit name. See the example below. You can also use this construct if you want all warnings off but some specific warning(s) on:
83+```
9284{$warnings off}{$warn <number> on}
9385```
9486
9587## Control Specific Warnings or hints per piece of code:
9688
97-You can control this very finely grained by using {\$push} and {\$pop} around a block of code. This does not have to be a method body as long it is a block, e.g. begin/end,repeat/until,/while do, try/finally etc.
98-
99-``` pascal
89+You can control this very finely grained by using {$push} and {$pop} around a block of code. This does not have to be a method body as long it is a block, e.g. begin/end,repeat/until,/while do, try/finally etc.
90+```
10091procedure withunusedparameter(const testme:integer);
101-{$push}{$warn 5024 off}
102-begin
103-//
104-end;
105-{$pop}
106-begin
107- withunusedparameter(100);
108-end.
92+ {$push}{$warn 5024 off}
93+ begin
94+ //
95+ end;
96+ {$pop}
97+ begin
98+ withunusedparameter(100);
99+ end.
109100```
110101
111102# Obtaining the warnings and hints numbers to suppress
112103
113-You can obtain the needed numbers by compiling your code once with line info on and with -vwhilq
104+You can obtain the needed numbers by compiling your code once with line info on and with -vwhilq
114105
115-This will show both the numbers and the messages and the line numbers where they are found.
106+This will show both the numbers and the messages and the line numbers where they are found.
116107
117-The other way to obtain hint, notice or warning number is to search inside FP repository for source of your current FPC version.
108+The other way to obtain hint, notice or warning number is to search inside FP repository for source of your current FPC version.
118109
119-All of the messages with its own description is stored in \<FPC source dir\>/msg/error\<language\>.msg
110+All of the messages with its own description is stored in <FPC source dir>/msg/error<language>.msg
120111
121-This file is also have header, which provides explanation how error/notice/hint/warning constants are constructed.
112+Note: the language codes are not all the same as the standard [[Language Codes|ISO 639-1 2-letter language codes]]. The current files are:
122113
123-For the English language it's contains following:
114+| File Name | Language
115+---|---
116+errorct.msg | Catalan / català
117+errord.msg | German / Deutsch (alternative, US-DOS)
118+errorda.msg | Danish / dansk
119+errordu.msg | German / Deutsch (UTF-8)
120+errore.msg | English (default)
121+errores.msg | Spanish / Español (CP 28605)
122+errorf.msg | French / français (CP 850)
123+| File Name | Language
124+---|---
125+errorfi.msg | French / français (ISO 8859-1)
126+errorhe.msg | Hebrew / עִברִית (CP 1255)
127+errorheu.msg | Hebrew / עִברִית (UTF-8)
128+errorid.msg | Indondesian / Indonesia
129+erroriu.msg | Italian / italiana
130+errorn.msg | Dutch / Nederlands
131+errorpl.msg | Polish / Polski (CP 852)
132+| File Name | Language
133+---|---
134+errorpli.msg | Polish / Polski
135+errorpt.msg | Portugese / portuguesa (CP 850)
136+errorptu.msg | Portugese / portuguesa (UTF-8)
137+errorr.msg | Russian / russa (CP 866)
138+errorru.msg | Russian / russa (UTF-8)
139+errorues.msg | Spanish / Español (CP 65001)
140+
141+This file also has a header, which provides explanation how error/notice/hint/warning constants are constructed.
124142
125-``` pascal
143+For the English language it contains the following:
144+```
126145# CodePage 20127
127-
128-#
129-# The constants are build in the following order:
130-# <part>_<type>_<txtidentifier>
131-#
132-# <part> is the part of the compiler the message is used
133-# asmr_ assembler parsing
134-# asmw_ assembler writing/binary writers
135-# unit_ unit handling
136-# option_ command line parameter parsing
137-# scan_ scanner
138-# parser_ parser
139-# type_ type checking
140-# general_ general info
141-# exec_ calls to assembler, external linker, binder
142-# link_ internal linker
143-# package_ package handling
144-#
145-# <type> the type of the message it should normally used for
146-# f_ fatal error
147-# e_ error
148-# w_ warning
149-# n_ note
150-# h_ hint
151-# i_ info
152-# l_ add linenumber
153-# u_ used
154-# t_ tried
155-# c_ conditional
156-# d_ debug message
157-# x_ executable informations
158-# o_ normal (e.g., "press enter to continue")
159-#
160-# <type> can contain a minus sign at the beginning to mark that
161-# the message is off by default. Look at type_w_explicit_string_cast
162-# for example.
146+
147+ #
148+ # The constants are build in the following order:
149+ # <part>_<type>_<txtidentifier>
150+ #
151+ # <part> is the part of the compiler the message is used
152+ # asmr_ assembler parsing
153+ # asmw_ assembler writing/binary writers
154+ # unit_ unit handling
155+ # option_ command line parameter parsing
156+ # scan_ scanner
157+ # parser_ parser
158+ # type_ type checking
159+ # general_ general info
160+ # exec_ calls to assembler, external linker, binder
161+ # link_ internal linker
162+ # package_ package handling
163+ #
164+ # <type> the type of the message it should normally used for
165+ # f_ fatal error
166+ # e_ error
167+ # w_ warning
168+ # n_ note
169+ # h_ hint
170+ # i_ info
171+ # l_ add linenumber
172+ # u_ used
173+ # t_ tried
174+ # c_ conditional
175+ # d_ debug message
176+ # x_ executable informations
177+ # o_ normal (e.g., "press enter to continue")
178+ #
179+ # <type> can contain a minus sign at the beginning to mark that
180+ # the message is off by default. Look at type_w_explicit_string_cast
181+ # for example.
163182```
164183
165-So, to find your warning/notice/etc, you just need to search the message body. For the example, it can be \<unit "Pas2Js.pas" not used in main.pas\>, to find this warning, you need to replace all of the local data in message body with \$\< data number \>,
166-
167-``` pascal
184+So, to find your warning/notice/etc, you just need to search the message body. For the example, it can be <unit "Pas2Js.pas" not used in main.pas>, to find this warning, you need to replace all of the local data in message body with $< data number >,
185+```
168186for this situation it will be: <Unit "$1" not used in $2>;
169187```
170188
171-After that, you can find the required message just by finding its body in errors\<language\>.msg file, you will find the following:
172-
173-``` pascal
189+After that, you can find the required message just by finding its body in errors<language>.msg file, you will find the following:
190+```
174191sym_n_unit_not_used=05023_H_Unit "$1" not used in $2
175-% The unit referenced in the \var{uses} clause is not used.
192+ % The unit referenced in the \var{uses} clause is not used.
176193```
177194
178-So, the actual notice number is 05023.
179-
180-Based on that number you can decide to suppress the warning or hint globally, per unit or per routine, depending on what you need.
195+So, the actual notice number is 05023.
181196
182-For example, if you want to suppress unused parameters you can subsequently compile with -vm5024.
197+Based on that number you can decide to suppress the warning or hint globally, per unit or per routine, depending on what you need.
183198
184-With the -vm compiler option you can use multiple warning and hint numbers separated by a comma. Or you can write:
199+For example, if you want to suppress unused parameters you can subsequently compile with -vm5024.
185200
186-``` pascal
201+With the -vm compiler option you can use multiple warning and hint numbers separated by a comma. Or you can write:
202+```
187203{$warn 5024 off}
188204```
189205
190-This needs to be done for each number separately.
206+This needs to be done for each number separately.
191207
192-See also:
208+See also:
193209
210+Directives, definitions and conditionals definitions
211+---
212+[[global compiler directives]] • [[local compiler directives]] · [[Conditional Compiler Options]] • [[Conditional compilation]] • [[Macros and Conditionals]] • [[Platform defines]] · [[$IF]]
213+
194214---
195-*From the Free Pascal wiki, page "Turn warnings and hints on or off", as it stood on 2020-03-02 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
215+*From the Free Pascal wiki, page "Turn warnings and hints on or off", as the Internet Archive kept it on 2025-02-11, last changed on 2024-10-10. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history