Registering classes in a module

Is there somewhere an example on how to include classes in a module ? All my attempt fail. This is what I actually do based on code found.

REALclassDefinition Class1_Definition = {
    kCurrentREALControlVersion,
    "Class1",
    ......
    ......
};

REALclassDefinition Class2_Definition = {
    kCurrentREALControlVersion,
    "Class2",
    ......
    ......
};

static REALclassDefinition All_Classes[] = {
    Class1_Definition,
    Class2_Definition
};

static REALclassDefinition* ac = All_Classes;
static REALclassDefinition** All_ClassDef = ∾


// Structures and enumerations live inside of a module,
// and so we will demonstrate how to declare them inside
// of the module.

static REALmoduleDefinition testModule = {
	kCurrentREALControlVersion,
	"TestStructEnumModule",
	testMethods,
	sizeof(testMethods) / sizeof(REALmethodDefinition),
	NULL,		// Constants
	0,			// Constant count
	NULL,		// Properties
	0,			// Property count
	testStructs,
	sizeof( testStructs ) / sizeof( REALstructure ),
	testEnums,
	sizeof( testEnums ) / sizeof( REALenum ),
    nil, // Atributes
    0, // Attribute count
    nil, // Delegates
    0, // Delegate count
    ClassDef, // Classes
    _countof(ClassDef), // Class count
};

void PluginEntry( void )
{
	REALRegisterModule( &testModule );
        // SetClassConsoleSafe(&Class1_Definition);
        // REALRegisterClass(&Class1_Definition);
        // SetClassConsoleSafe(&Class2_Definition);
        // REALRegisterClass(&Class2_Definition);
}

Doing so auto-complete doesn’t show the classes after the first one.

Var c2 As TestStructEnumModule.Class2
IDE complains that Class2 is an unknown type. Classes registered indepently work fine.

One more question. From my knowledge it is not possible to declare structures in a class. Why ?

Thanks in advance for your advices.

ClassDef, // Classes
_countof(ClassDef), // Class count

Are you sure this is right?

Should it be:

All_Classes, // Classes
_countof(All_Classes), // Class count = 2

and I don’t see ClassDef above defined.

Christian,

I meant All_ClassDef instead ClassDef.

I tried what you’re suggesting but I get :

.......
.......
0, // Delegate count
ALL_Classes, // Classes Cannot initialize a member subobject of type 'REALclassDefinition **' with an lvalue of type 'REALclassDefinition [2]'
_countof(All_Classes), // Class count
};
&All_Classes, // Classes
_countof(All_Classes), // Class count = 2

Add an & there?

Same kind of error. Just a bit different.

 nil, // Delegates
   0, // Delegate count
    &All_Classes, // Classes Cannot initialize a member subobject of type 'REALclassDefinition **' with an rvalue of type 'REALclassDefinition (*)[2]'
    _countof(All_Classes), // Class count
};
</small>

Your compiler is picky:

&All_Classes[0]

maybe like this with [0] on the end?

Classes need to be set up like this:

static REALclassDefinition* MyClasses[] =
{
&MyClass1,
&MyClass2,
};

Thats basically his error that their set up wrong.

1 Like

Björn,

That did the trick !!!

Thanks a lot both of you

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.