Page 1 of 1

ClientData mysery

Posted: Tue Apr 13, 2021 5:11 pm
by ONEEYEMAN
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.

Re: ClientData mysery

Posted: Tue Apr 13, 2021 5:23 pm
by doublemax
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