Recent

Author Topic: Hint: Parameter "Sender" not used ?  (Read 11632 times)

majid.ebru

  • Hero Member
  • *****
  • Posts: 530
Hint: Parameter "Sender" not used ?
« on: February 05, 2018, 10:55:09 am »
Hi

in my program , i have many this hint (and an other hints) :

unit_Main.pas(1594,30) Hint: Parameter "Sender" not used

what do i do?

i should clear? or ....??

thankyou
« Last Edit: February 05, 2018, 10:58:22 am by majid.ebru »

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Re: Hint: Parameter "Sender" not used ?
« Reply #1 on: February 05, 2018, 11:13:09 am »
You may just not pay attention to it.
If you want a cleaner messages box, you may right-click this message and Hide this message by inserting {$warn ... off} to unit "...".
« Last Edit: February 05, 2018, 11:14:54 am by Eugene Loza »
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Hint: Parameter "Sender" not used ?
« Reply #2 on: February 05, 2018, 11:29:35 am »
If it's a hint about standard component etc. I'd ignore it but if its something you've declared then it might be worthwhile to take notice.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4709
  • I like bugs.
Re: Hint: Parameter "Sender" not used ?
« Reply #3 on: February 05, 2018, 12:39:32 pm »
You may just not pay attention to it.
If you want a cleaner messages box, you may right-click this message and Hide this message by inserting {$warn ... off} to unit "...".
It is safer to use the
 "Hide message by inserting IDE directive {%H-}".
It only hides the one message you wanted to hide.

See also under project options: Compiler Options -> Verbosity -> 'Show hints for parameter "Sender" not used'.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

zeljko

  • Hero Member
  • *****
  • Posts: 1906
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Hint: Parameter "Sender" not used ?
« Reply #4 on: February 05, 2018, 02:09:42 pm »
See also under project options: Compiler Options -> Verbosity -> 'Show hints for parameter "Sender" not used'.

Definitelly better than polluting source with {%H-}

majid.ebru

  • Hero Member
  • *****
  • Posts: 530
Re: Hint: Parameter "Sender" not used ?
« Reply #5 on: February 05, 2018, 07:43:22 pm »
project options: Compiler Options -> Verbosity -> 'Show hints for parameter "Sender" not used'.

thankyou

i unchecked it.

but i have many hint:
Code: Pascal  [Select][+][-]
  1. unit_Main.pas(1712,54) Hint: Parameter "Shift" not used
  2. .
  3. unit_Main.pas(1710,7) Hint: Parameter "MousePos" not used
  4. .
  5. unit_Main.pas(1715,29) Hint: Parameter "Handled" not used
  6. .
  7. unit_Main.pas(1757,30) Hint: Parameter "X" not used
  8. unit_Main.pas(1757,30) Hint: Parameter "Y" not used
  9. //    procedure P_P1_9_ACMouseDown(Sender: TObject; Button: TMouseButton;
  10. //      Shift: TShiftState; X, Y: Integer);
  11. .
  12. unit_Main.pas(1699,51) Hint: Parameter "Button" not used
  13. .
  14. .
  15. .
  16. .
  17. .
  18. .
  19.  

for these hints , what do i do?

PatBayford

  • Full Member
  • ***
  • Posts: 125
Re: Hint: Parameter "Sender" not used ?
« Reply #6 on: February 06, 2018, 07:20:50 am »
Depends what they are - if they are unused variables/parameters, just remove them - search/replace is great for this.
The most common reason for this is when you use the code generator to start your event handlers, but you don't need all the standard passed parameters.
Lazarus 1.8.0 FPC 3.0.2 SVN 56594 Windows 10 64bit (i386-win32-win32/win64)

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4709
  • I like bugs.
Re: Hint: Parameter "Sender" not used ?
« Reply #7 on: February 06, 2018, 04:35:21 pm »
Depends what they are - if they are unused variables/parameters, just remove them - search/replace is great for this.
The most common reason for this is when you use the code generator to start your event handlers, but you don't need all the standard passed parameters.
You cannot remove parameters from event handlers because their signature must match the events.
The compiler shows an error if you try to assign such wrong handler in code.
Unfortunately the form streaming system does not check the signature. It means you can change it in code and no error is shown when loading an LFM file, but later unpredictable errors may occur.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Hint: Parameter "Sender" not used ?
« Reply #8 on: February 06, 2018, 07:56:53 pm »
You cannot remove parameters from event handlers because their signature must match the events.
The compiler shows an error if you try to assign such wrong handler in code.

Too bad we can not remove the identifier and leave the type:
Code: Pascal  [Select][+][-]
  1.     procedure Button1Click(: TObject);

wp

  • Hero Member
  • *****
  • Posts: 13485
Re: Hint: Parameter "Sender" not used ?
« Reply #9 on: February 06, 2018, 10:57:49 pm »
Hints and warnings are not bad: they give you an indication that something MAY be wrong. After long debugging sessions I found many a bug immediately once I decided to look at the hints and warnings in the message window!

The problem is that there are so many of them. You can modifiy the source code to get rid of them (e.g., add that {%H-} directive mentioned above, or call dummy procedures "Unused(Sender, x, y)" like TAChart does). But the problem is that modifications in the source code are difficult to revert.

At the application level the best thing is to go to the project options, "Compiler options" > "Messages": type in the "Filter" line part of the massage phrase "not used" and you will see only the related messages. Uncheck them and rebuild the project --> the hints and warnings will be gone. The point is that this did not change the source code, just the project file - if you later need the hints and warnings back you just do the same and check them again.

This was already written above, but maybe you did not catch the point.

dbannon

  • Hero Member
  • *****
  • Posts: 3777
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Hint: Parameter "Sender" not used ?
« Reply #10 on: February 07, 2018, 04:34:25 am »
Said WP

Quote
"Compiler options" > "Messages": type in the "Filter" line part of the massage phrase "not used" and you will see only the related messages. Uncheck them ....

Good tip WP. Is there an equivalent when we use Lazbuild ? Its so much wordier and I live in terror of missing something important .....

(I do use --quiet --quiet but it does not offer fine grain control.)

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1226
    • Burdjia
Re: Hint: Parameter "Sender" not used ?
« Reply #11 on: February 07, 2018, 05:56:00 pm »
That hint is just to warn you that may be you are not using the procedure/function properly.  On events I recommend you to use the Sender parameter.

Anyway, you can avoid that hint by code, like re-assigning it.  For example:
Code: Pascal  [Select][+][-]
  1.   PROCEDURE TMyClass.AnEvent (Sender: TObject);
  2.   BEGIN
  3.     Sender := Sender;
  4.     ... Do things here ...
  5.   END;
  6.  

The compiler will optimize it and do nothing.  If parameter is CONST you can do:
Code: Pascal  [Select][+][-]
  1.   PROCEDURE MyProcedure (CONST aParam: INTEGER);
  2.   BEGIN
  3.     IF aParam <> aParam THEN EXIT;
  4.     ... Do things here ...
  5.   END;
  6.  

Again, the compiler will optimize it in most cases.

I prefer the "code" way instead of the "directive" way because it is more visible.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

ASerge

  • Hero Member
  • *****
  • Posts: 2481
Re: Hint: Parameter "Sender" not used ?
« Reply #12 on: February 07, 2018, 10:33:12 pm »
Code: Pascal  [Select][+][-]
  1.   PROCEDURE TMyClass.AnEvent (Sender: TObject);
  2.   BEGIN
  3.     Sender := Sender;
  4.     ... Do things here ...
  5.   END;
  6.  

Code: Pascal  [Select][+][-]
  1.   PROCEDURE MyProcedure (CONST aParam: INTEGER);
  2.   BEGIN
  3.     IF aParam <> aParam THEN EXIT;
  4.     ... Do things here ...
  5.   END;
  6.  
In both cases, an extra code is generated.
If you are ready to make changes to the source code, then as indicated by @wp, you can use the procedure.
I propose a procedure that, unlike TAChart, does not generate code at all.
Code: Pascal  [Select][+][-]
  1. {$PUSH}
  2. {$WARN 5024 OFF : Parameter "$1" not used}
  3. procedure Unused(const P: Pointer); inline; overload;
  4. begin
  5. end;
  6.  
  7. procedure Unused(const I: Integer); inline; overload;
  8. begin
  9. end;
  10.  
  11. procedure Unused(const S: string); inline; overload;
  12. begin
  13. end;
  14. {$POP}
  15.  
  16. procedure Test(Param1: Integer; const Param2: string);
  17. begin
  18.   Unused(Param1);
  19.   Unused(Param2);
  20. end;
  21.  
  22. procedure TForm1.FormCreate(Sender: TObject);
  23. begin
  24.   Unused(Sender);
  25.   Test(1, '2');
  26. end;
The generated code is the same as if there were no calls to Unused at all.

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1226
    • Burdjia
Re: Hint: Parameter "Sender" not used ?
« Reply #13 on: February 08, 2018, 12:34:22 pm »
@ASerge: That solution looks nicer and better than mine. I should remember it.
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12770
  • FPC developer.
Re: Hint: Parameter "Sender" not used ?
« Reply #14 on: February 08, 2018, 04:03:55 pm »
In a past job, we had a solution like {%h-} that filters compiler output integrated into the build automation tool.

It would save both the filtered and unfiltered log, and some filters were more permanent (like all Kylix related warnings in D7, to avoid having to flag them all).

There was a plan to further extend the principle with types of warnings (something like {%H- 5045,5046} to suppress only warning 5045 and 5046 on that line, but I changed jobs, so never saw that.

 

TinyPortal © 2005-2018