 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
François Charton Guest
|
Posted: Fri May 20, 2005 5:07 pm Post subject: Enumerating all the controls of a given type |
|
|
Hello,
Is there a simple way to find all the instances of a given type of control
(or its descendents) in an application?
What I want to achieve, for instance, would be to change the color of all
TPanels (or TPanel descendents) in my app. Something like :
tp=GetFirstPanel();
while(tp) {
tp->Color=NewColor;
tp=GetNextTPanel(tp);
}
where GetFirstPanel/GetNextPanel would iterate on all instantiated TPanels
or descendents... without habing to maintain an external list of all TPanels
(which would be very difficult to keep complete as the application evolves).
Thanks in advance
Francois
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri May 20, 2005 5:23 pm Post subject: Re: Enumerating all the controls of a given type |
|
|
"François Charton" <fcharton (AT) carthage (DOT) fr> wrote
| Quote: | Is there a simple way to find all the instances of a given type
of control (or its descendents) in an application?
|
You have to loop over every control one at a time, querying their type
information.
| Quote: | What I want to achieve, for instance, would be to change the color
of all TPanels (or TPanel descendents) in my app.
|
{
for(int x = 0; x < Screen->FormCount; ++x)
ChangePanelsColor(Screen->Forms[x], NewColor);
}
void __fastcall ChangePanelsColor(TWinControl *ParentControl, TColor
NewColor)
{
for(int x = 0; x < ParentControl->ControlCount; ++x)
{
TControl *ctrl = ParentControl->Controls[y];
if( TPanel *pnl = dynamic_cast<TPanel*>(ctrl) )
pnl->Color = NewColor;
if( TWinControl *wctrl = dynamic_cast<TWinControl*>(ctrl) )
ChangePanelsColor(wctrl, NewColor);
}
}
Gambit
|
|
| Back to top |
|
 |
François Charton Guest
|
Posted: Mon May 23, 2005 8:21 am Post subject: Re: Enumerating all the controls of a given type |
|
|
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> a écrit dans le message de news:
428e1cde$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
You have to loop over every control one at a time, querying their type
information.
What I want to achieve, for instance, would be to change the color
of all TPanels (or TPanel descendents) in my app.
{
for(int x = 0; x < Screen->FormCount; ++x)
ChangePanelsColor(Screen->Forms[x], NewColor);
}
void __fastcall ChangePanelsColor(TWinControl *ParentControl, TColor
NewColor)
{
for(int x = 0; x < ParentControl->ControlCount; ++x)
{
TControl *ctrl = ParentControl->Controls[y];
if( TPanel *pnl = dynamic_cast<TPanel*>(ctrl) )
pnl->Color = NewColor;
if( TWinControl *wctrl = dynamic_cast<TWinControl*>(ctrl) )
ChangePanelsColor(wctrl, NewColor);
}
}
|
Thank you very much, Remy!
Francois
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|