Class Windows

When you create a window called Window1, you create a class Window1, which is a subclass of Window in a module with the same name. So the full classname is actually Window1.Window1.

If ImplicitInstance is set to yes – unfortunately the standard –, a function with the same name is created in this module, which returns the instance and creates the instance on the first call). So you can access the Window1 instance without having to create it with New beforehand.

If you want to really subclass Window you must insert one or more subclass layer between Window and Window1. Then you can re-use this “inserted” subclass for more than one window. This is how to do it:

Do “Insert –> Class” in the menu.
Give it a name like MyWindowSubclass.
Change its Super to Window.
Add any code you want to MyWindowSubclass.
Create a window (or select an existing one in the navigator) and change its Super to MyWindowSubclass.
Create a second window (or select another existing one in the navigator) and change its Super to MyWindowSubclass.

So you have this hierarchy:

Class Window (Xojo framework) Class MyWindowSubclass (a class, not a window) Class Window1 (the actual class & instance in the window designer)

In my projects I usually have something like this:

Class Window Class DocumentWindow (class only) Class MainWindow (class only) Class ProductWindow (window designer class & instance) Class ContactWindow (window designer class & instance) Class InvoiceWindow (window designer class & instance) ... Class ReportWindow (window designer class & instance) ... Class DialogWindow (class only) Class AboutWindow (window designer class & instance) Class PreferencesWindow (window designer class & instance) Class CancelWindow (window designer class & instance) Class MessageWindow (window designer class & instance)
As you see there is multiple subclassing: Window –> DocumentWindow –> MainWindow –> ProductWindow.