ClientData mysery Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5222
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

ClientData mysery

Post by ONEEYEMAN » Tue Apr 13, 2021 5:11 pm

Hi, ALL,
1. Is this proper/legitimate way:

Code: Select all

MyDialog::MyDialog(...)
{
    m_myListBiox = new wxListBix( ... );
    ......
}

void MyDialog::SomeFunc()
{
    wxString test = "data";
    m_myListBox->Append( "String1", &test );
}
2. If the code is correct - how do I get back the "data"?

I know I should use pointer to set the client data, but its just an overkill for such simple case.

Thank you.

User avatar
doublemax
Moderator
Moderator
Posts: 16176
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: ClientData mysery

Post by doublemax » Tue Apr 13, 2021 5:23 pm

If you use the overload that takes a "void*", the object must be allocated on the heap and you're responsible for deleting it.

If you use the overload that takes a "wxClientData*", the object must also be allocated on the heap but the listbox takes ownership and deletes it.

If you only want to store a string, you can use wxStringClientData.
https://docs.wxwidgets.org/trunk/classw ... _data.html

You get the object back using wxItemContainer::GetClientObject()
https://docs.wxwidgets.org/trunk/classw ... 171e7fb98c
Use the source, Luke!

Post Reply