Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting a frame.

Status
Not open for further replies.

Tremorblue

Programmer
Apr 30, 2004
56
GB
I dynamically create frames at run time and put them in a panel.
The frame has a button on it to allow the user to delete the frame.

What code should I use to delete the frame ?
delete (this); is causing random errors.

At the moment I have a work around but I'd like to know the "proper" way to do this.

/Thanx
TB.
 
I haven't had much luck looking into this but it seems to me that instead of delete(this) you should use delete(framename).


James P. Cottingham
-----------------------------------------
I'm number 1,229!
I'm number 1,229!
 
The this pointer is a pointer to the object that you're in; it is inherent in all classes and as a result, your code results in the class that you're in trying to delete itself. I suspect you tried to do something like this
Code:
TPanel * this;
... 
this = SomePanel;
...
delete(this);
All vcl components have a method RemoveComponent which you should use to remove and delete child components. Try something like this instead:
Code:
// create and insert new frame
TFrame *Someframe = new TFrame(this);
this->InsertComponent(SomeFrame);
...
//delete frame
this->RemoveComponent(Someframe);

Remove component takes carer of deleting the component for you.

The simplest solution is the best!
 
I have some similar situation within one application as I dinamically create and delete tab sheet pages. The "Close Page" button is right on the sheed about to be closed and deleted so I couldn't do the job right away, as I would delete the object calling the method.

So I just hide the sheet, and the removal process happends at a later time.

The code below might be useful for you:


ticketSheet->PageControl = NULL;
//
// My own clean process
//
ticketSheet->Delete();

pageControl->Refresh();
delete ticketSheet;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top