Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of the 'Tag' property of Delphi VCL components?

Tags:

Is there any specific purpose for the 'Tag' property of Delphi VCL components? I have Googled a few examples using it as, for example, a 'color' property or using the value as a pointer address, but is it 'good practice' to use it, or is it considered 'bad practice' as it ties the program logic to the UI?

like image 709
HMcG Avatar asked Nov 06 '09 21:11

HMcG


1 Answers

The "tag" property is there as a "cargo container" for whatever you might want to do with it.

Something it's often used for is in event handlers when you have a lot of similar components sharing one event handler. The event handler can find its caller and then query its tag value to get some more information about what it's supposed to be acting on.

EDIT:

Example: A calculator app might tag the number buttons with their respective numbers... silly and incomplete example, but you get the idea. The event handler could then pull the number to add into the display and accumulator right out of the tag instead of having to go figure out which button is meant to do what.

like image 142
Carl Smotricz Avatar answered Sep 19 '22 14:09

Carl Smotricz