I can delete shapes as it's very simple, but deleting shapes that belong to a certain parent I cannot do.

For example, deleting all TShape elements that share the parent "group".

I'm unsure of how to do this, can anyone lead me in the right direction? or tell me its not possible at least.

Recommended Answers

All 7 Replies

I can delete shapes as it's very simple, but deleting shapes that belong to a certain parent I cannot do.

For example, deleting all TShape elements that share the parent "group".

I'm unsure of how to do this, can anyone lead me in the right direction? or tell me its not possible at least.

Can you give some code, I don't understand the problem.

Shape1->~TShape();

This is the deleting too. [SMILE]

Can you give some code, I don't understand the problem.

Ah i have a lot of code, it's hard to see where I would put this function.

Basically it's a little game, a basis for something larger. Random numbers are dealt between 1 and 10 and the player begins with say two shapes within a group box which is used to contain hisor her starting shapes. Each shape has a mousedown event which, when activated, will use Sender to 'pick up' the shape, if you will.

There are two more group boxes for a bet, one for betting the next number will be higher, and one for lower.

I have already written code for processing a win, which is to add two times the number of shapes the user has bet in the correct groupbox, back to the starting group box.

What i want to do is delete all the shapes in the group box where the result was wrong.

I hope this makes sense!

Shape1->~TShape();

This is the deleting too. [SMILE]

I'm not sure what you mean by that, could you explain a little?

The code would be something like

delete all TShape* where TShape parent = grpbox; (i know that's not real code but still)

>What i want to do is delete all the shapes in
>the group box where the result was wrong.
Maintain a list of pointers to shape objects that are added to the group box. Then when you want to delete all of the shapes in the group box, it's as simple as this:

for ( int i = 0; i < list.size(); i++ )
  delete list[i];

the problem is, each shape will end up sharing the same name, as I have code in place to create x amount of shapes with a correct guess. Will this affect the list?

>Will this affect the list?
No, the object's data has nothing to do with the pointer that points to it. You'll have issues if you try to store a pointer to the same object in the list more than once (because you'll try to delete it more than once), but if each pointer points to a unique object, you're good.

ok thanks a lot for the replies, i will try that but seeing as my c++ builder keeps giving me a No Disk error, I wont be able to for a little while.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.