Subclasses in Plugin SDK

Hi

I cannot find any example online or in the Xojo installation which deals with subclasses in a plugin.

Is there any example C/C++ code for a plugin to expose a system of classes like the following:

Class A
   Sub X()
      ...
   End Sub
End Class

Class B Inherits A
   Sub Y()
      ...
   End Sub
End Class

Where is the question?

You can register a class in a plugin, which mentions another class as SuperClass and we do so frequently in our plugins.

Thanks Christian.

The question is, does there exist a simple example of this?

I ask because I cannot find such an example in the Xojo Examples folder, or plugin SDK docs, nor through searching online.

There may be no example.
Do you have problems?

You could just put a super class name into the field for REALClassDefinition.

e.g.

REALclassDefinition CFStringClass = {
	kCurrentREALControlVersion,
	"CFStringMBS",
	"CFObjectMBS",
	0,
	0,
	nil,
...

where top is new class and bottom name is super class.

In the example folder look for Complete Class.

Extras\PluginsSDK\Examples\Complete Class\CompleteClass.cpp

Then look for “REALclassDefinition TestClassDefinition”

You will see a base class definition (subclass of nil)

If it were a subclass of something, that name would be there instead of nil, as “SomeSuperClass”.

There you will see exactly what Christian said.

Do you have problems?

For example:

REALmethodDefinition members[] = {
	{ (REALproc)X, REALnoImplementation, "X()", REALconsoleSafe }
};

REALclassDefinition A_class_definition = {

	kCurrentREALControlVersion,
	"A",
	nil,
//...
	members,
	_countof(members),
//...
};

void X(REALobject instance)
{
    ClassData(A_class_definition , instance, /* some type */, me);
}

//...

REALclassDefinition B_class_definition = {

	kCurrentREALControlVersion,
	"B",
	"A",
//...
};

In void X(), I need to know if the most-derived type of instance is B or A to select the correct REALclassDefinition.

But void X() should be defined in a way which has no knowledge of B because it is a member of the base class.

I think I have now solved this by REALObjectISA combined with a vector<REALclassDefinition*> pre-populated with pointers to all REALclassDefinition known to the plugin. This looks up correct REALclassDefinition to use for any instance.

Alternatively I could force all my subclasses to implement all overridden methods which I guess would work.

But I’d love to know if there is a ‘proper’ way to achieve this, hence the original post.

In X, you just use A_class_definition as the class X belongs to.
Or if you need data of super class, you could use the super_class_definition.

No need for vector or REALObjectISA.

It makes sense now.

My mistake was that I was only implementing either the base class constructor or the derived class constructor, but not both. I now see I need to implement both to have the right data available in each scope.

Thank you for your help.