Главная страница | назад





Article #17381: Turning several Labels into array of labels

 Question and Answer Database
FAQ2381C.txt Turning several Labels into array of labels
Category :VCL
Platform :All
Product :C++Builder 3.x
Question:
Say, I have ten labels in my form. Label1 through Label10.
For me to clear them all, I have to write ten lines, as
opposed to three line loop that would take care of them all.
How can I convert these Label1 through Label10 into
Label[10] type of a deal so that I can deal with them
impersonally with mass-production age callousness?
Answer:
There are several ways to attack this problem. If the form you're creating
is dynamic, you can build them dynamically into the form. However, if
you're using the visual designer to build them (ie. using the GUI) then you
can do some interesting things based on the names of the labels. Here's a
code fragment that might help...
//---------------------------------------------
TLabel *theLabel;
int i;
char labelName[10];
for(i = 0; i < 10; i++)
{
sprintf(labelName, "Label%d", i);
theLabel = static_cast(FindComponent(labelName));
if(theLabel)
theLabel->Caption = "";
}
//---------------------------------------------
7/2/98 10:32:32 AM

Last Modified: 01-SEP-99