Board index » delphi » Using the Tag Property

Using the Tag Property

I am tring to address an objects properties through its tag value.  That
is:  Is there a way to say "The object whom tag is equal to 1, set its
caption to 'I''m Tag One'"?  It sure seemed like an easy thing to figure
out, but I haven't :(.

Carolyn

 

Re:Using the Tag Property


In article <312A61A6.3...@cclink.fhcrc.org>, "Carolyn J. Burns" <cjbu...@cclink.fhcrc.org> says:
Quote

>I am tring to address an objects properties through its tag value.  That
>is:  Is there a way to say "The object whom tag is equal to 1, set its
>caption to 'I''m Tag One'"?  It sure seemed like an easy thing to figure
>out, but I haven't :(.

>Carolyn

Hello Carolyn,
Seems to me that that component should be easy to find:

  for i:=0 to ComponentCount-1 do
    if Components[i] is tWinControl then
    Begin
        if tWinControl(Components[i]).tag=1
        then tWinControl(Components[i]).Caption := 'I''m component 1';
    End;

Does this help?
Jochen
________________________________________________________________________
joch...@berlin.snafu.de                        74754.2...@compuserve.com
I post, therefore I am.

Re:Using the Tag Property


In article <312A61A6.3...@cclink.fhcrc.org>, "Carolyn J. Burns"
<cjbu...@cclink.fhcrc.org> writes
Quote
>I am tring to address an objects properties through its tag value.  That
>is:  Is there a way to say "The object whom tag is equal to 1, set its
>caption to 'I''m Tag One'"?  It sure seemed like an easy thing to figure
>out, but I haven't :(.

Suppose you have a series of TEdit components, each with a different Tag
value set at design time. Set the OnClick event for all of them to a
single procedure with the following type of code,

procedure TForm1.Edit1Click(Sender: TObject);
begin
  case (Sender as TEdit).Tag of
    1: (Sender as TEdit).Text := 'Tag 1';
    2: (Sender as TEdit).Text := 'Tag 2';
    3: (Sender as TEdit).Text := 'Tag 3';
    ...
  end;
end;

If you don't want to change a property in an event handler, then you
will have to iterate all the components. Look up the Components property
in on-line help. It gives a code example. Come to think of it you should
have looked at the Tag property in on-line help first of all :)
--
Barney Tyrwhitt-Drake

Re:Using the Tag Property


On Tue, 20 Feb 1996 16:04:54 -0800, "Carolyn J. Burns"

Quote
<cjbu...@cclink.fhcrc.org> wrote:
>I am tring to address an objects properties through its tag value.  That
>is:  Is there a way to say "The object whom tag is equal to 1, set its
>caption to 'I''m Tag One'"?  It sure seemed like an easy thing to figure
>out, but I haven't :(.

Just the hard way:

for I := 0 to ComponentCount-1 do
  if (Components[I].Tag = 1) and (Components[I] is TLabel) then
    TLabel(Components[I]).Caption := 'I''m Tag One';

If you need to do this a lot, then write a method do it for you, e.g.,
FindTagComponent(Tag: LongInt): TComponent
--
Ray Lischner         (li...@tempest-sw.com)
Tempest Software, Corvallis, Oregon, USA

Re:Using the Tag Property


Quote
Carolyn J. Burns wrote:

> I am tring to address an objects properties through its tag value.  That
> is:  Is there a way to say "The object whom tag is equal to 1, set its
> caption to 'I''m Tag One'"?  It sure seemed like an easy thing to figure
> out, but I haven't :(.

> Carolyn

You need to loop through the compnents on the form You will also learn
alot about Casting the components to their respective object types. Look
at the Components Property of the Scroll Box might give you a hint.

jr!
--
----------------------------------------------------------------------
Jim Roberts                      jrobe...@interaccess.com
James Roberts Computer Consulting            708/658-9409
----------------------------------------------------------------------

Other Threads