Quantcast

wxDVC model ownership troubles

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

wxDVC model ownership troubles

Vadim Zeitlin-4
 Hello (Robert),

 I'm trying to use wxDVC in a "real" program for the first time and while
it is definitely great (i.e. it allows me to do exactly what I want) I
sometimes have real trouble understanding how is it supposed to work.

 First, and so far the most important, of the problems I have with it is
that it seems the control can't own its own model. To be more precise, I
want to create a fa├žade for wxDataViewCtrl which exposes just the simple
API that I need. So for me it makes sense to define a custom model and
create (and destroy) it directly in my wxDataViewCtrl-derived class.
Unfortunately if I destroy this model in the derived class dtor, the base
class dtor crashes as it still tries to reference it. And if I try to call
AssociateModel(NULL) before deleting it, this crashes immediately as the
generic wxDataViewCtrl::AssociateModel() dereferences the passed in model
without checking that it's non-NULL (in spite of the fact that the base
class version does check for it).

 So is AssociateModel(NULL) supposed to be called? If not, how else can I
detach the model from the control? And if I can't, how am I supposed to
delete it if I want to keep it encapsulated and not force the user of my
class to do it?

 The only solution I see right now is to not derive my custom class from
wxDataViewCtrl any more but make it a container for wxDataViewCtrl and its
model. This will work, of course, but is less convenient as I'd still like
to call various wxWindow methods (e.g. SetSize() or Hide/Show()) on it, so
I'd need to have a GetWindow() accessor and use it. Still possible -- and
this is what I'll probably end up doing -- but I wonder if the current
situation could really have been intentional and also if I'm just missing
something obvious here (which would be the best case).

 TIA,
VZ

_______________________________________________
wx-dev mailing list
[hidden email]
http://lists.wxwidgets.org/mailman/listinfo/wx-dev

attachment0 (194 bytes) Download Attachment
Loading...