Difference between revisions of "Turn warnings and hints on or off"

From Free Pascal wiki
Jump to navigationJump to search
Line 13: Line 13:
 
Problem is that this hint turns up all over the place and I know what it means. How do I get rid if it?
 
Problem is that this hint turns up all over the place and I know what it means. How do I get rid if it?
  
=== Lazarus IDE options ===
+
== Lazarus IDE options ==
 +
The Lazarus IDE can control hints and warnings in two ways:
 +
* Globally through the Project Options menu
 +
* Using an IDE macro
  
== Global option ==
+
 
 +
=== Global IDE option ===
 
Go to the Project Options->Compiler Options->Messages and uncheck 'Hint:Paramater "$1" not used'.<br>
 
Go to the Project Options->Compiler Options->Messages and uncheck 'Hint:Paramater "$1" not used'.<br>
 
This will turn of this particular hint for your whole project.<br>
 
This will turn of this particular hint for your whole project.<br>
Line 22: Line 26:
  
 
[[File:lazarusglobal.png]]
 
[[File:lazarusglobal.png]]
 +
<br>
 +
 +
=== Local IDE option ===
 +
In the Lazarus IDE you can make use of the {%H-} IDE macro to turn hints off for a particular parameter.<br>
 +
Of course {%H+} will turn hints on.
 +
<syntaxhighlight>
 +
    procedure FormMouseDown(Sender: TObject; {%H-}Button: TMouseButton;
 +
      {%H-}Shift: TShiftState; {%H-}X, {%H-}Y: Integer);
 +
</syntaxhighlight><br>
 +
Note that this turns off ALL hints for that parameter, not just the 'is not used' hint, so be careful.
 +
 +
== Source code options ==
 +
The options as described above will only work within the Lazarus IDE.<br>
 +
It won't work in any other IDE, not even de FPC textmode IDE. The compiler output will still emit warnings and hints<br>
 +
Luckily there are several other options to control hints and warnings in the source code itself.
 +
* control all warnings per unit: add <syntaxhighlight>{$warnings off}</syntaxhighlight> or resp. <syntaxhighlight>{$warnings on}</syntaxhighlight> just after the unit name.<br><br>
 +
* control all hints per unit: add <syntaxhighlight>{$hints off}</syntaxhighlight> or resp. <syntaxhighlight>{$hints on}</syntaxhighlight> just after the unit name.<br><br>
 +
* control all warnings per piece of code:
 +
* control specific warnings per unit
 +
* control specific warnings per piece of code
 +
 +
= TODO =

Revision as of 12:08, 14 May 2017

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.

procedure TForm.Button1Click(sender:Tobject);
begin
  // DoSomethingThat does not use sender
  Form1.Button1.Caption := 'Test';  
end;

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 get rid if it?

Lazarus IDE options

The Lazarus IDE can control hints and warnings in two ways:

  • Globally through the Project Options menu
  • Using an IDE macro


Global IDE option

Go to the Project Options->Compiler Options->Messages and uncheck 'Hint:Paramater "$1" not used'.
This will turn of this particular hint for your whole project.
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'.


lazarusglobal.png

Local IDE option

In the Lazarus IDE you can make use of the {%H-} IDE macro to turn hints off for a particular parameter.
Of course {%H+} will turn hints on.

    procedure FormMouseDown(Sender: TObject; {%H-}Button: TMouseButton;
      {%H-}Shift: TShiftState; {%H-}X, {%H-}Y: Integer);


Note that this turns off ALL hints for that parameter, not just the 'is not used' hint, so be careful.

Source code options

The options as described above will only work within the Lazarus IDE.
It won't work in any other IDE, not even de FPC textmode IDE. The compiler output will still emit warnings and hints
Luckily there are several other options to control hints and warnings in the source code itself.

  • control all warnings per unit: add
    {$warnings off}
    or resp.
    {$warnings on}
    just after the unit name.

  • control all hints per unit: add
    {$hints off}
    or resp.
    {$hints on}
    just after the unit name.

  • control all warnings per piece of code:
  • control specific warnings per unit
  • control specific warnings per piece of code

TODO