Board index » cppbuilder » Re: Control caption?

Re: Control caption?


2006-11-03 09:54:46 PM
cppbuilder23
"Dev Support" < XXXX@XXXXX.COM >wrote:
Quote

[...] The iteration is working fine however, I cannot seem
to find a way to edit the control's caption property???
Be aware that when using the form's Controls array, you will
only be itterating the controls that are directly parented by
the form. If, for example, you have dropped a label on a panel,
you won't find that label unless you code a recursive function
call.
Try this code instead:
for( int x = 0; x < ComponentCount; ++x )
{
TLabel *pLabel = dynamic_cast<TLabel*>( Components[x] );
if( pLabel )
{
pLabel->Caption = "Test";
pLabel->Update();
}
}
~ JD
 
 

Re:Re: Control caption?

Quote
[...] however, cannot seem to find a way to edit the control's
caption property???
// ...
#include <TypInfo.hpp>
// ...
void __fastcall TForm1::Button1Click(TObject *Sender)
{
for( int i=0; i<ControlCount; i++ )
{
TControl *pCtrl = Controls[ i ];
PPropInfo pPropInfo = GetPropInfo( pCtrl, "Caption", TTypeKinds() <<
tkString << tkLString << tkWString );
if ( pPropInfo )
SetStrProp( pCtrl, pPropInfo, "SomethingNew" );
}
}
--
Best Regards,
Vladimir Stefanovic
 

Re:Re: Control caption?

Hello all:
This is a follow up to an issue that you all helped me with a few weeks
back.
I am trying to iterate through all controls on a form and set their caption
property if the control is a label. The iteration is working fine however, I
cannot seem to find a way to edit the control's caption property??? Thanks
in advance for your help!
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int c = 0;
for (c = 0; c < Form1->ControlCount; c++)
{
TControl& t = *Form1->Controls[c];
if (t.ClassName() == "TLabel")
{
t.Caption = "Test"; // <<=========Caption not accessible!
}
}
}
Thank you
Marshall
 

{smallsort}

Re:Re: Control caption?

"Dev Support" < XXXX@XXXXX.COM >wrote:
Quote

Does the dynamic cast allow me to use the TLabel object
allow me without a new and delete?
Yes. pLabel is just another pointer to an already-existing
object but it has limited scope making it valid only for the
duration of a single itteration of the loop.
~ JD
 

Re:Re: Control caption?

JD:
Thank you for the info.
BTW: Does the dynamic cast allow me to use the TLabel object allow me
without a new and delete?
Thank you
Marshall
"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"Dev Support" < XXXX@XXXXX.COM >wrote:
>
>[...] The iteration is working fine however, I cannot seem
>to find a way to edit the control's caption property???

Be aware that when using the form's Controls array, you will
only be itterating the controls that are directly parented by
the form. If, for example, you have dropped a label on a panel,
you won't find that label unless you code a recursive function
call.

Try this code instead:

for( int x = 0; x < ComponentCount; ++x )
{
TLabel *pLabel = dynamic_cast<TLabel*>( Components[x] );
if( pLabel )
{
pLabel->Caption = "Test";
pLabel->Update();
}
}

~ JD

 

Re:Re: Control caption?

JD:
Good stuff!
Thanks a lot for the help!
Thank you
Marshall
"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"Dev Support" < XXXX@XXXXX.COM >wrote:
>
>Does the dynamic cast allow me to use the TLabel object
>allow me without a new and delete?

Yes. pLabel is just another pointer to an already-existing
object but it has limited scope making it valid only for the
duration of a single itteration of the loop.

~ JD