Reputation: 43
I've declared some methods which occasionally get used for debugging only. For example:
// For debugging purposes only
{$IFDEF DBG}
procedure SaveLUTs();
{$ENDIF}
These methods are used rarely and only if DBG is defined. If the method is not used the following compiler warning is generated:
[Hint] Hardware.pas(184): Private symbol 'SaveLUTs' declared but never used
Apart from commenting out the method declaration and body, is there a way to mark SaveLUTs
so that the compiler won't generate the warning? I still need the usual warnings to be generated, including warnings about other declared methods or variables that are not used.
Using Delphi 7 and interested in how this might be done for newer versions of Delphi as well.
Upvotes: 4
Views: 1770
Reputation: 11217
Another option would be to change the visibility of these methods from private to protected. If they are not private, the compiler will no longer complain.
This of course has the drawback of the methods no longer being private.
Upvotes: 1
Reputation: 125651
You don't need to disable hints. You can do it all with your {$IFDEF DBG}
, and have the symbol only compiled and used when the define is there. I use this frequently with code that encrypts a file and emails it when testing, because I don't want the encryption to happen or the email sent with the attachment.
unit Hardware;
interface
{.$DEFINE DBG} // Remove . to include debugging code
uses
SysUtils;
// Other procedure defs
procedure DoSomething;
procedure DoAnotherThing;
{$IFDEF DBG}
procedure SaveLuts;
{$ENDIF}
implementation
{$IFDEF DBG}
procedure SaveLuts;
begin
// Code here
end;
{$ENDIF}
procedure DoSomething;
begin
// Code here
end;
procedure DoAnotherThing;
begin
// Code here
end;
end.
In the unit where you want your debugging code used:
procedure Main;
begin
DoSomething;
{$IFDEF DBG}
SaveLuts;
{$ENDIF}
DoAnotherThing;
end;
The problem with disabling hints is that other code can sneak in inside the point where they're disabled and before they're reenabled. I don't like turning them off, because they can cause things to be missed that I didn't intend to happen.
Upvotes: 2
Reputation: 6467
You can flag the method like this :
{$Hints Off}
procedure SaveLUTs();
{$Hints On}
That will remove the hint for this procedure.
Note that {$Hints ON}
will enable hints for the rest of the unit regardless of the previous $Hints state. Since {$IFOPT}
doesn't work with long-named directives (At least, up to Delphi 10 Seattle...), I don't know of any way to restore the previous state.
Upvotes: 7