A few days ago, I asked such a question: "Five Button's OnClick events correspond to the name of the five Label", because the BCB has no control array, so everyone's answer is mostly RTTI, yesterday When I read "C Primer", I suddenly remembered the VECTOR type in the standard library. We also use this type to implement an array of controls.
Today, I tried it, I wrote the process of the experiment here. First include the header file and set the namespace, declare the variable. In mainform.h:
#include
USING NAMESPACE STD // Standard Library's namespace
Declaring Vector
Note that here I want to initialize the array in the form of Vector
Then add two button and a label on the main form, and in the event of Button1, this array is initialized.
For (int i = 0; i <5; i )
{
TLABEL * label = new TLABEL (this);
Label-> Parent = Form1;
Label-> TOP = 20 * i;
Test.push_back (label);
}
Test.push_back (testLabel); // Test if the array can contain a static generated control. The array at this time should be included in 6 member variables.
Write the following code in Button2:
For (int i = 0; i { TEST [I] -> CAPTION = "Wolf" Ansistring (i): } This example generates an array of controls by assigning a array cycle, and operates this array through a loop. The use of the VECTOR data type is only a very shallow, and C STL technology can give our programming greater freedom and elasticity. The above code is compiled in the Win2000 and BCB5 environments.