Class 'simple' Question

Novice XOJO programmer and struggling with own defined classes.

Using ‘traditional’ classes (with properties, methods…) in XOJO is similar to Java. This is not a great problem. But, how can I put a window (with listbox, textfields, buttons…) in a new class (e.g. MyClass)?

In a sense, a Window is already a class.

You design it and give it a name.
When you want a new one, you instantiate it:

dim mW1 as new  MyWindow

It can have public methods and functions…

a window IS a class.
you can put classes and windows in a single module if you want.

If I understand what you are asking, you’d like to create a class with listboxes and textfields already embedded into a Window Class, so that when that Window Class is subclassed, that it would already have the listboxes and textfields already in place?

If my assumption is correct above, then the answer is that Window classes don’t behave that way in Xojo. What you are looking for is a Container class. They are the mechanism to “group” other classes together to work. You would then drop that Container onto a Window (or web page) and when instantiated, you’d see all of the controls along with their inherited methods and properties.

Hope this helps.

@Kevin, your assumption is correct. In Java this is straightforward: you can put several classes in a new defined class. In XOJO this is impossible. The basics of XOJO are so easy, but when you want to use some ‘advanced’ topics then XOJO is a complex programming environment. I still have problems with e.g. ContainerControls (I know how to use them, but it is still unclear to me WHEN to use them), Control Sets (I can use it, however it is unclear why you have to start with a first (sometimes unhidden) control…

To return to your reply: can I put a container in a user-defined class (e.g. MyClass)?

@Carlos De Backer — The way I understand your question is that you would want a self-contained object which contains a Window object and that you can just copy&paste from one project to another, and it just works.

In Xojo, containers (module, class…) are limited in the type of objects they can store. The most versatile is the Folder: not only can it have otherwise forbidden characters in its name, but also it can contain anything, including Windows. The second most versatile is the Module, but I do not think it can contain Windows.

About Window subclasses, note that any Window you create with e.g. Insert>Window, is a subclass of Window. However, you cannot subclass further those windows in Xojo (but you can do it with a plugin).

@Stephane Mons. “In fact, modules can pretty much contain anything except layouts such as Windows, Web Pages, Views and Container Controls.” (XOJO User guide). So, no Windows in modules… I thought, folders and folderItems only refer to file system data. Is it more versatile?

@Carlos De Backer — A Xojo Folder has nothing to do with a folder on disk. A Xojo folder can contain any objects: modules, classes, modules which contain classes, windows and so on.

Folders in the IDE are abstract constructs… They do not exist except within the IDE to group other items

@Stphane @Dave OK, I never used folders in the IDE. So, folders can be used to group all kind of data (windows, self-defined classes, variables…). But, a folder is not a class and thus cannot be instantiated… Is this correct?

that is correct

@Carlos De Backer — Yes you can store anything in a folder and you can copy&paste it from a project to another. All other containers have limitations

You cannot put a Window inside a class. Why not? Because Windows, while they appear to be classes, are in fact not classes. This article explains what was, and still is, the set up:

https://web.archive.org/web/20071015210521/http://ramblings.aaronballman.com:80/2007/06/

[quote=418016:@Jason Parsley]You cannot put a Window inside a class. Why not? Because Windows, while they appear to be classes, are in fact not classes. This article explains what was, and still is, the set up:

https://web.archive.org/web/20071015210521/http://ramblings.aaronballman.com:80/2007/06/[/quote]

Technically a Window IS a class… it just is a class that has very specific restrictions

Windows’ lives matter! (or anything that makes sense in English)

When it comes time to compile your project a Window is a module that contains a class with the same name - and a method with the same name if you have implicit instantiation turned on. And there may be lots of other items in this module depending on how your project is set up. But the primary item that is compiled is a module. Not a stand alone class.
The IDE hides this from you. But some of the reality leaks out - like why you cannot put a Window inside a class.

Thanks Jason, that is very informative.

However, it would be possible to make a Xojo Window a true object which could be:
1. Subclassed in Xojo (and not only in plugins)
2. Included in many more Xojo objects

@Jason Parsley @Dave S I like this article: the article explains very well why a private constructor in a window is not accepted. (I tried this 2 days ago). Only a public constructor can be added to a window!

[quote=418025:@StphaneMons]Thanks Jason, that is very informative.

However, it would be possible to make a Xojo Window a true object which could be:
1. Subclassed in Xojo (and not only in plugins)
2. Included in many more Xojo objects[/quote]

No.

  1. you cannot inherit UI - so that’s a bit of a show stopper right there
  2. the contents of this module is, in part, are what makes the window work the way it does and rearchitecting that is unlikely to happen

What you can already do is add a class that has a super of Window and then when you create new windows set their super to this newly created class. This way you are not inheriting UI but can insert your own superclass and whatever functionality you need / want into that.

Oh no !! As a French, I will have to read/listen that article before I can tell my opinion! It puts me well behind all the idiots who don’t listen or don’t care!!

PS: This is a joke!! Even if I am French.