I want to delete old images I created in a for loop.
The first time clicking the Button the images are created. The second time or third, whatever, the old Images that were created should now be deleted (before the loop) and then directly recreated in the loop.
Because I am getting the Image
properties from the database and when someone changed something in the database you should be enabled to get the newest Image properties from the database.
I tried it with delete Image[i]
, free()
and delete[]
(whole Array) but I am always getting an Access Violation Error. Here is my following code:
TImage *Image[c]= ; //c is 5
I want to delete the old Images here and then create the new in the loop below
for (int i = 0; i < c; i++)
{
str = " Test "
Image[i] = new TImage(this);
Image[i]->Parent = BoardItem ;
Image[i]->Height = 20 ;
Image[i]->Width = 20 ;
Image[i]->Position->X = d ; // The program asks you the coordinate at the begining of a new loop
Image[i]->Position->Y = e ;
Image[i]->Bitmap = Icon->Bitmap ;
Image[i]->StyleName = str ;
Image[i]->OnClick = ImageClick ;
}
You must delete single image by simple delete
operator like:
for (int i = 0; i < c; i++)
{
delete Image[i];
// NULL deleted pointer
Image[i] = NULL;
}
Access Violation also may be caused because you still use this images somewhere in your code. And why did you want delete this images? As they are pointers you may simple renew values.
To reserve values for unpredictable amount of pointers TImage*
you can use:
TImage** ppImage= NULL;
than create amount of pointers you want:
ppImage = new TImage*[c];
after that you may work with those pointers like you did before.