REALcontrolDefinition vs REALclassDefinition

I’m testing a possible transfer of some controls from Xojo to a plugin (it’s my first try to develop a serious plugin). I’m trying two different solutions:

a) implementing them as subclasses of RectControl by using REALcontrolDefinition
b) implementing them as subclasses of Canvas by using REALclassDefinition

Since I’m only interested in implementing subclasses in Cocoa, but also want to compile for Windows and Linux, the latter case is more interesting. There would be no necessity to implement the Windows and Linux part like one has to do when subclassing from RectControl.

I did some test over the weekend to decide on this. Everything works well, only the control subclassed from REALclassDefinition is not showing on runtime, though it does properly behave in the IDE.

First I looked at all the properties in Xojo in the debugger: they give back the correct values, methods do too, and I can also set properties and query them, everything works fine - the control is just not showing (though Visible is True).

Then through declares I queried the Objective C Runtime instances. They also gave me the correct values, for example:

  • the superview is equivalent of the Handle property of the Xojo canvas
  • the frame is equivalent of the Bounds property of the Xojo canvas (it also resizes correctly when the canvas resizes)

When I try the same in Xojo (adding an NSView to a Canvas subclass with the help of “Declare” statements), the added NSView is showing. Why does the Canvas subclass not show, when adding the NSView to a Canvas subclass in a plugin? I’m using the exact same commands (“alloc”, “initWithFrame:”, “addSubview:”, etc.).

When developing controls, I would highly recommend to go with REALcontrolDefinition and check the examples. The framework will help you a lot with doing a lot of things to keep it working right.

The docs say: [quote]Note that controls automatically have a superclass of RectControl, or if the REALinvisibleControl flag is set, Control. If you wish for your control to have a different superclass, then you must declare them as a REALclassDefinition.[/quote] So it is viable to subclass a Xojo Canvas.

I’d have to second Christian on this one. If you use REALcontrolDefinition, you get a bunch of stuff for free. On Cocoa, you get lots of behavior for free, like automatically having its frame set or being in the proper place in the view hierarchy.

For an example on how to do this, see the HostedPluginExample that ships with the plugins SDK.

I don’t want to be impolite, but what is the benefit of telling me twice: don’t do it that way. As mentioned, the docs say it’s possible. So please answer my question or give me a hint what I could be doing wrong or what I could have forgotten or or or…

…and otherwise: just don’t answer!

Well, of course you can subclass any class. But you waste your time there coding all the stuff again you get for free with the control.
And we are answering on a voluntary basis. There is no guarantee for correctness nor that someone answers at all.