Using the VCL control array in BCB 2

Source: Internet
Author: User
Tags comparison

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.