My "BCB use of VCL control array", mentioned the use of tlist to achieve when the problem is not to release resources, the results today got the answer, Yan Hua and so on netizens all advise the tlist implementation of the release method, the definition of code in the previous text:
for (int i=1;i<=buttoncount;i++)
{
Tspeedbutton *spdbtn=new Tspeedbutton (this);
spdbtn->parent=scrollbox;//Specifies the parent control
Spdbtn->caption=inttostr (i);
spdbtn->width=80;
spdbtn->height=80;
spdbtn->onclick=buttonclick;
spdbtn->left=intleft;
spdbtn->top=inttop;
spdbtn->groupindex=1;
spdbtn->flat=true;
Intleft=intleft+80+intspace;
if (i%linecount==0)
{
Inttop=inttop+80+intspace;
Intleft=intspace;
}
Buttons->add (SPDBTN);//buttons is a tlist pointer.
}
The code to release the resource is as follows:
int num = button->count;
for (int i=0;i<num;i++)
{
Delete (Tspeedbutton *) button->items[i];
}
In fact, it is to delete every item of tlist, but because the type of tlist->items is void *, in C + +, void * Can match any type, so just add a force type conversion (Tspeedbutton *), of course ( TObject *) is also possible because the TObject is the base class for all classes in VCL, and the pointer to the base class is a direct or indirect subclass that can point to it.
Comparison of two methods: My last method was a typical C + + solution, this method can be said to be a c++builder solution, with a dual pointer is more flexible and efficient, but we all know that multiple pointers can not be so understood, think I had used 4 pointer (don't use that look at me!)! Until later, I was confused by myself. And this method comparison understood, and can use Tlist class method, use more convenient, but not as high as an efficient, in general, the two methods have advantages and disadvantages, specific use that kind of, see personal preferences.