Board index » delphi » Tag property what is it used for?

Tag property what is it used for?

I've seen a few demos that used the tag property, but still don't
understand it's primary purpose or best usage.

Any comments or suggestions would be helpful.

 

Re:Tag property what is it used for?


Quote
Vincent Taijeron wrote:
> I've seen a few demos that used the tag property, but still don't
> understand it's primary purpose or best usage.

Use it for any long integer you want associated with a component, but
don't want to go deriving new classes to store.  For example, in a
system of button-driven menus, you might set the tag to be true when a
button has been clicked to store that it has been visited.  However it's
more powerful than that, because other types can be casted to a long
integer, one of the most useful of which is a pointer, so you could
indirectly make the tag refer to a string, or even another object; I
used the latter to create a simple linked list of components and in this
particular case it was a lot neater than using the TList construct.

--
David Gosnell
These personal views are not necessarily those of my employer.

Re:Tag property what is it used for?


Quote
Vincent Taijeron wrote:

> I've seen a few demos that used the tag property, but still don't
> understand it's primary purpose or best usage.

        The whole point to tag is that it doesn't have a "primary"
purpose, so that you're free to use it for whatever you want (as
long as you're certain nobody else is using it for something else,
of course.)

--
David Ullrich

?his ?s ?avid ?llrich's ?ig ?ile
(Someone undeleted it for me...)

Re:Tag property what is it used for?


Quote
David Ullrich wrote:

> Vincent Taijeron wrote:

> > I've seen a few demos that used the tag property, but still don't
> > understand it's primary purpose or best usage.

Best Usage I have seen was for security, where components were given
different
security tag values and a generic "visitor" pattern could then visit all
the
components in the form to enable/disable all of the allowable ones. By
using the
components array you never needed to know what the component was only
whether
its tag value was high enough to be enabled.

--
Euan Garden                    
BusinessMetrics? Development Team

Email: e...@valstar.co.uk
Web: http://www.valstar.co.uk
---------------------------------------------------
The opinions expressed here are my own
and not those of my employer

Re:Tag property what is it used for?


Quote
redl...@worldnet.att.net (Vincent Taijeron) wrote:
>I've seen a few demos that used the tag property, but still don't
>understand it's primary purpose or best usage.

>Any comments or suggestions would be helpful.

The tag property can be used for anything the programmer wants to use it for.
I use it extensively as an 'identifier' in common event handlers, to indentify
which Checkbox, Radiobutton, etc. was actually activated.  IE:

procedure handleClickEvent(Sender : TObject);

begin
....
  case (Sender as TCheckBox).Tag of
      1 : do something;
      2 : something else;
      3 : anything else;
  end // case

<etc, etc>

------------------
Thomas Hill, dba t.h.ink Software
email: hi...@ionet.net
wwww: http://www.ionet.net/~hillt
(Check out the IIS ISAPI extention DLL examples at my Web site)
---------
"Being politically correct means always saying you're sorry"

Re:Tag property what is it used for?


Quote
In article <33abe508.136481...@news.ionet.net> real-addr...@bottom.of.page (Thomas Hill) writes:
>>I've seen a few demos that used the tag property, but still don't
>>understand it's primary purpose or best usage.

>>Any comments or suggestions would be helpful.
>The tag property can be used for anything the programmer wants to use it for.
>I use it extensively as an 'identifier' in common event handlers, to indentify
>which Checkbox, Radiobutton, etc. was actually activated.  IE:
>procedure handleClickEvent(Sender : TObject);
>begin
>....
>  case (Sender as TCheckBox).Tag of
>      1 : do something;
>      2 : something else;
>      3 : anything else;
>  end // case
><etc, etc>

Yeah, it's a nice feature, really.  You see, lots of different objects can
point their event-properties to the same subroutine, and then you need a
convenient way to tell them apart.  One way, if you don't want to deal with
"Sender," is to use a tag.

Remember, when you click on an event-property, in addition to the "..." button
or the double-click there *is* a drop-down list available!  Every procedure
which has the right parm-list is going to be included in that list.  Any
number of objects can point to that procedure and share the code that way.

Other Threads