wxString ref counting

Armel armelasselin at hotmail.com
Fri Apr 11 10:05:01 PDT 2008




"spiralguru" <scott.wakeling at gmail.com> a écrit dans le message de news: 
mailman.110.1207930810.19501.wx-users at lists.wxwidgets.org...
>
> I have a wxString that I am setting to the return value of
> wxTextCtrl->GetValue().
>
> When the dialog that contains the wxTextCtrl deletes itself, the pchData 
> of
> *my* string is destroyed. I want a *copy* of the text in the text control,
> not a *reference* to it. How can I do this!? I am surprised the text gets
> deleted when I am holding a reference to it!
>
> e.g.
>
> mCurrProjectName = dlg.GetProjectName(); // i.e. return
> mpTextCtrl->GetValue();
>
> //dlg now goes out of scope and deletes the text that mCurrProjectName is
> referencing
>
> mCurrProjectName = ... // blows up, tries to dereference what it's 
> currently
> pointing at but the reference is now garbled and wxString explodes
>
>
> How can I GetValue() on that text ctrl and have my string survive the dlg
> destroying?
just take care of returning or storing your value as a ' wxString' not a 
'(const) wxString &', the reference counting will then do its job correctly.

Regards
Armel




More information about the wx-users mailing list