Class inside a Class

Is it possible to create a class definition INSIDE another class Definition?

I don’t mean an instance of ClassB used by ClassA, I mean so they are both encapulated in a single class.

Take for example. ClassA is a database class, and ClassB is a database record class,
can the definiton of ClassB be inside ClassA, where ClassA can instantiate instances from the internally define class

One reason is that ClassA and ClassB need to share code (and I would like to NOT create a Module, giving me 3 pieces)
and the primary reason, is so that all can be inside a single encrypted custom class object with no need for external resources

Like in Java? As far as I know, its not possible directly. Maybe you could use a Xojoscript object and make your ClassA the context? I think that may be the closest you can get to defining a class inside of another class.

Dang… ClassA holds a bunch of format info that applies to EVERY instance of CLASSB, and I was hoping to minimize that memory consumption as there will be possible thousands of instances of ClassB, but ClassB cannot access properties of CLASSA without knowing the specific instance of ClassA :frowning:

You can create a Namespace and put the classes inside of it. Example: We have BKS_Shorts which is a namespace module. There are many classes inside of it and to the user it appears as one module but to reference those objects you have to use the namespace. BKS_Shorts.Document, BKS_Shorts.Page, etc. Sounds like that will might do what you need.

Well, if you only need a single instance of ClassA then you could use a singleton and ClassB could access the instance with ClassA.getInstance() or similar.

No you cant put one class inside another

There an FR for that though

Ok… So I created a Module, and was able to move ClassB into it
ClassB is inherited from Object (it has no super)
but ClassA is inherited from a CANVAS, and it will NOT let me move that class into the Module…

am I doing something wrong?

[quote=168109:@Dave S]Ok… So I created a Module, and was able to move ClassB into it
ClassB is inherited from Object (it has no super)
but ClassA is inherited from a CANVAS, and it will NOT let me move that class into the Module…

am I doing something wrong?[/quote]

Strange. I just tried putting a customcanvas inside a module and it works just fine.

I have tried to drag it… cut it then paste it and nobody what I do, the canvas based class ends up back at the root

Could it be that container controls are not allowed to be in a Module???

you can do it with controls
container control is more a window than a control so you can’t add to a module

Windows & container controls are special in many ways
No you cant stuff them in a namespace (module)

But you said it was derived from a canvas ?

This CAN be put in a module

I did say that… forgetting it was a canvas inside a container control … my bad

I created a class with super ContainerControl, and it can be added to a module. But it does not show in the IDE as a container control. Same thing for a window.

However, when dragged over a window it does show up, and if I set the backcolor true it shows as well.

yes, in that case it’s a class, I use a lot this kind of class

In a module you can’t put a visual class (where you have controls in it)

[quote=168109:@Dave S]Ok… So I created a Module, and was able to move ClassB into it
ClassB is inherited from Object (it has no super)
but ClassA is inherited from a CANVAS, and it will NOT let me move that class into the Module…

am I doing something wrong?[/quote]

Good question IMHO. Should then get Class A get as a namespace instead of a Real class?

I realize it’s not possible what I asked without subclassing and wanted to delete my question. Or IDE is wrong ( I’m getting more confortable with it and did not allow me to add a Class inside a Class ) or… nevermind…

Forum edit bug is soooo annoying… I wanted to delete my question.

NP
I just wondered

But yes its a known thing you cannot put a window or container in a module

There’s an FR to make that possible