Recent

Author Topic: [Solved] How important is it to use “sender”  (Read 1086 times)

Kraig

  • New Member
  • *
  • Posts: 26
[Solved] How important is it to use “sender”
« on: November 20, 2023, 01:29:06 pm »
I often get warnings that “sender was not used”.
I’m doing fairly simple  things where the sender is the control itself. To use the sender:tobject  I would have to do type checking and Type casting. It seems like a lot of extra effort.
I can understand the idea of using sender if more than one type of control was being sent to the procedure which would cause different things to happen. Am I being too lazy by not using sender? What’s the worst thing that can happen?
« Last Edit: November 21, 2023, 01:14:18 am by Kraig »

Zvoni

  • Hero Member
  • *****
  • Posts: 2744
Re: How important is it to use “sender”
« Reply #1 on: November 20, 2023, 01:33:27 pm »
I often get warnings that “sender was not used”.
I’m doing fairly simple  things where the sender is the control itself. To use the sender:tobject  I would have to do type checking and Type casting. It seems like a lot of extra effort.
I can understand the idea of using sender if more than one type of control was being sent to the procedure which would cause different things to happen. Am I being too lazy by not using sender? What’s the worst thing that can happen?

If you use one Event-Handler for multiple controls, Sender is your only way to find out, which control fired it.
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Kraig

  • New Member
  • *
  • Posts: 26
Re: How important is it to use “sender”
« Reply #2 on: November 20, 2023, 01:37:34 pm »
Yes I sometimes do that and in that case I do check what the sender is before using it.

Bart

  • Hero Member
  • *****
  • Posts: 5469
    • Bart en Mariska's Webstek
Re: How important is it to use “sender”
« Reply #3 on: November 20, 2023, 06:10:33 pm »
Am I being too lazy by not using sender? What’s the worst thing that can happen?

That depends on what you do in the event.
In most cases it's probably irrelevant who/what Sender is.
As others have pointed out, you can assing 1 eventhandler to multiple components, and in such a case it may very well be relevant who the sender is.
Only you, the programmer, knows if this is the case.

Bart

Kraig

  • New Member
  • *
  • Posts: 26
Re: How important is it to use “sender”
« Reply #4 on: November 21, 2023, 01:13:21 am »
Thanks for the answers

 

TinyPortal © 2005-2018