Re: CListCtrl, custom item data and allocation policy
- From: "AliR \(VC++ MVP\)" <AliR@xxxxxxxxxxxxx>
- Date: Wed, 16 Jan 2008 20:34:48 GMT
This is a good example of where to use inheritance. You can have
CMyListCtrl use DWORDs and then inherit from CMyListCtrl and have it use
pointers.
The overriding of the Delete methods is all up to you and it depends on how
you will be using the class. If your CListCtrl class does all the memory
allocation and ItemData setting independent of the outside then yes you
should override any method that deletes an item so that you can delete the
structure that your class created, and don't forget to catch the destroy
message and traverse the remaining items and delete their data before the
control gets destroyed.
If on the other hand the ItemData is being assigned from outside of the list
control class, then I would say no, let the class that creates the data
handle the deleting of the data.
AliR.
"Mosfet" <anonymous@xxxxxxx> wrote in message
news:478e6385$0$2739$426a74cc@xxxxxxxxxxxxxxx
Hi,
When using a CListCtrl you can associate some custom data via the
SetItemData method.
The problem is it takes a DWORD argumentr that can reference a value or a
pointer to an allocated structure.
When destroying this CListCtrl is there any ways of determining if it
needs to be deallocated.
For instance, let's say I have a CMyListCtrl inheriting from CListCtrl
used in two different dialogs.
In one dialog I call SetItemData passing a DWORD value representing a
numeric value and in the second one I pass a pointer to an allocated chunk
of memory.
In the destructor how doI know if I need to call delete ?
.
- References:
- CListCtrl, custom item data and allocation policy
- From: Mosfet
- CListCtrl, custom item data and allocation policy
- Prev by Date: Re: CListCtrl, custom item data and allocation policy
- Next by Date: Re: Are these libraries standard libraries
- Previous by thread: Re: CListCtrl, custom item data and allocation policy
- Next by thread: Re: CListCtrl, custom item data and allocation policy
- Index(es):
Relevant Pages
|