BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Enumerating all the controls of a given type

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
François Charton
Guest





PostPosted: Fri May 20, 2005 5:07 pm    Post subject: Enumerating all the controls of a given type Reply with quote



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





PostPosted: Fri May 20, 2005 5:23 pm    Post subject: Re: Enumerating all the controls of a given type Reply with quote




"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





PostPosted: Mon May 23, 2005 8:21 am    Post subject: Re: Enumerating all the controls of a given type Reply with quote




"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.