On Time RTOS-32 Documentation
Welcome
RTTarget-32
RTKernel-32
RTFiles-32
RTIP-32
RTPEG-32
RTPEG-32 Programming Manual
Introduction
Overview
Programming with RTPEG-32
Application Program Structure
Rules Of Memory Ownership
Creating PegThings
Deleting/Removing PegThings
Obtaining a Pointer to PegPresentationManager
Finding an Object's Parent
Finding an Object's Children
Status Flags
Style Flags
Determining the Position of an Object
Using Object Types
Using Object IDs
Messages
Overriding the Message() Method
Drawing to the Screen
Overriding the Draw() Method
Drawing to Memory
Using PegTimer
Viewports
Fonts
Scrolling
Screen Drivers
Demo Programs
Utility Programs
RTPEG-32 Reference Manual
RTUSB-32
|
Deleting/Removing PegThings
Removing a PegThing (i.e. a window, button, dialog, or other object derived from PegThing) from its parent is not the same as deleting it. Removing an object takes it out of the active display tree. After being removed, the object no longer has a parent, and it will not be visible. It is possible, even common, to later re-add the object to a visible PegThing and use it over again.
A PegThing is removed by calling the PegThing member function Remove(PegThing * What). It doesn't matter if the parent object removes a child, or if a child removes itself, because the Remove() function properly handles either case. That is, it is perfectly acceptable to use the following statement:
Remove(this);
when an object decides based on some message input that it is time to go away.
While Remove() can be useful, it is more common to want to both remove the object from its parent, as well as delete the object from memory. There are three acceptable ways to remove and delete an object:
- Sending a PM_DESTROY message to PegPresentationManager. The pSource member of the PM_DESTROY message should point to the object which is to be destroyed. This method is most often used when deleting objects from tasks outside of RTPEG-32.
- Calling the PegThing member function Destroy(PegThing * Who). Any PegThing can destroy any other PegThing, including itself. This does not mean that the Destroy() function will end up executing a delete(this) statement. The Destroy function checks to see if Who == this, and in this case automatically sends a PM_DESTROY message to PegPresentationManager to finish the job.
- If a PegThing is already removed from its parent through use of the Remove() function, and the object to be deleted is not this, nor is this a child of the object being deleted, it is fine to simply delete the object.
One should never execute delete(this). When in doubt, it is always safe to call Destroy(). It is not necessary to manually delete the individual children of a PegThing, in fact it will cause errors if this is attempted.
Programming with RTPEG-32
Creating PegThings
Obtaining a Pointer to PegPresentationManager
|