Forum > Beginners

[Solved] How important is it to use “sender”

(1/1)

Kraig:
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?

Zvoni:

--- Quote from: Kraig 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?

--- End quote ---

If you use one Event-Handler for multiple controls, Sender is your only way to find out, which control fired it.

Kraig:
Yes I sometimes do that and in that case I do check what the sender is before using it.

Bart:

--- Quote from: Kraig on November 20, 2023, 01:29:06 pm ---Am I being too lazy by not using sender? What’s the worst thing that can happen?

--- End quote ---

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:
Thanks for the answers

Navigation

[0] Message Index

Go to full version