[wx-dev] wxListCtrl::SetItemData why is it a long?

Mario A. Velasco Sánchez mavelasco at oficsa.com
Wed May 9 10:18:59 PDT 2007


> What is really needed for wxPython is the equivalent of 
> wxItemContainer::SetClientObject which takes a wxClientData* and also 
> takes ownership of that pointer so it can delete it when the item is 
> removed from the list.

I have used wxListItem::SetData to get the same functionality.  Maybe adapt 
this to wxListCtrl will be easier than a SetClientObject function, something 
that would be very useful to have.  Using wxClientData makes you don't worry 
about macros like this, to delete the pointers:

#define MACRO_DEL_LISTDATA(obj_List, className) \
    { \
        className * data_del; \
        long item_del = -1; \
        item_del = obj_List->GetNextItem(item_del, \
            wxLIST_NEXT_ALL, wxLIST_STATE_DONTCARE); \
        while (item_del != -1) \
        { \
            data_del = (className*)(obj_List->GetItemData(item_del)); \
            if (data_del) \
            { \
                delete data_del; \
            } \
            item_del = obj_List->GetNextItem(item_del, wxLIST_NEXT_ALL, \
                wxLIST_STATE_DONTCARE); \
        } \
    }





More information about the wx-dev mailing list