Re: Get|SetControlProperty() equivalent
Re: Get|SetControlProperty() equivalent
- Subject: Re: Get|SetControlProperty() equivalent
- From: Jo Meder <email@hidden>
- Date: Fri, 12 Jun 2009 01:25:30 +1200
Hi Graham,
On 11/06/2009, at 11:50 PM, Graham Cox wrote:
The carbon mechanism exists because in classical procedural code,
you can't subclass an "object" because there is no formal "object"
to subclass. Therefore storage mechanisms have to be provided to
hang extra stuff on.
It's still just a convenience rather than a necessity, there are
other ways of doing it. It's a useful convenience though, in this
case at least.
In Cocoa, we have proper objects, so you can simply (ingeniously!)
subclass the NSControl or NSView as you wish and add any extra data
members you want for any purpose you wish. For example you could
subclass NSView and add a reference to your C++ object directly as
a data member along with suitable accessors for it. If the view
needs to be aware of the C++ code itself you can compile it as
Objective-C++ using a .mm extension on the source file.
It's not really so simple, because I'd have to subclass all the views/
controls I use, which is many of the UI elements available, and that
means I have many disparate classes implementing the same
functionality. Of course I then need to repeat that for any new
controls I support. Less work and maintenance to maintain a map from
NSViews to my C++ framework objects. I should have mentioned I had
considered and rejected subclassing I guess.
As an aside, I'm using Objective-C++ extensively in my framework.
It's quite the godsend really and has made things a lot quicker and
easier.
Thanks anyway. I was a long time MacZoop user BTW. Well, some of
MacZoop, I used all my own control classes. I use a messaging and
commander system inspired by my experience with MacZoop in my own
framework.
Regards,
Jo Meder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden