Board index » delphi » Setting Tag Property at runtime?

Setting Tag Property at runtime?

I'm trying to set the tag property of controls (Tbutton) at runtime.  I get
no error, but the value doesn't stick.  I've tried explicitly casting to
integer and long integer, but no go.

Any ideas?

****************************************************************************
***
 While NOT IBQry.Eof DO
      Begin
      With TButton(FindComponent(Format('Product%d', [intCount]))) DO
         Begin
         Tag := LongInt(IBQry.fieldByName('MenuItemID').AsInteger);
         Caption := IBQry.FieldByName('Me{*word*198}scription').AsString;
         end;
      //End With
      intCurrentFree := intCount + 1;
      intCount := intCount + 1;
      If (intCount = 29) Then Exit;
      IBQry.Next;

      End;

 

Re:Setting Tag Property at runtime?


OK,

I figured it out.  When running the application from within the IDE, after
the tag property of controls is set it doesn't show it's value when placing
the cursor over it (D6E) for some reason.  When running the exe, I showed a
Messagebox with the value of the tag property and it was correct.

Lee

Re:Setting Tag Property at runtime?


I would recommend that you take
TButton(FindComponent(Format('Product%d', [intCount]))) out of the
with statement and assign it to a specific TButton type variable.
That way you'll be able to debug it a bit easier.  You could also do a
check to see that the control really is a button by using "If oControl
is TButton".  Then use "(oControl as TButton)".

I'm not 100% sure whether FindComponent returns a copy of the button
or the actual button reference.  This may be the reason the value
doesn't "stick".

Cheers,
Kevin.

Quote
"Lee Jenkins" <lee_jenkin...@datatrakpos.com> wrote in message <news:2KvW7.109509$RE3.21160073@typhoon.southeast.rr.com>...
> I'm trying to set the tag property of controls (Tbutton) at runtime.  I get
> no error, but the value doesn't stick.  I've tried explicitly casting to
> integer and long integer, but no go.

> Any ideas?

> ****************************************************************************
> ***
>  While NOT IBQry.Eof DO
>       Begin
>       With TButton(FindComponent(Format('Product%d', [intCount]))) DO
>          Begin
>          Tag := LongInt(IBQry.fieldByName('MenuItemID').AsInteger);
>          Caption := IBQry.FieldByName('Me{*word*198}scription').AsString;
>          end;
>       //End With
>       intCurrentFree := intCount + 1;
>       intCount := intCount + 1;
>       If (intCount = 29) Then Exit;
>       IBQry.Next;

>       End;

Re:Setting Tag Property at runtime?


Thanks Kevin,
Will do.

Lee

Other Threads