Hey guys, me again…
I am learning about Classes and I was wondering: how come, when I create a subclass from, a canvas for example, the subclass stays separate and when I drag the class on a window, it creates a new item, similar to when you do it from the library. But if I do it with a window, it does not act the same. Is that a normal way to behave?
Not sure I follow what it is you’re trying to do ?
You cant drag a Window onto a Window if that’s what you mean ?
@Norman Palardy : you are right, of course. What I meant is that I would like to keep it separate so that if I update the subclass, the instance created by it would also be updated. Come to think of it, could I just create a window and set the subclas to the one I created, in fact doing manually what Xojo is doing when we are dragging a control of the window?
A follow up question: if my subclass works nicely and that i would like to refer to it regulrly, is there a way to include it in the Control library in a more pemanent fashion than having to drag the subclass in each project I create?
That’s how all subclasses work. What is not being updated in the window instance. (The window class you create can only contain logic, of course, no layout. Right?) Updating the logic in the window class will affect the instance.
@Tim Hare : Thank you.
Now, if I add properties to a subclass of a canvas, for example, I can go in the Inspector Behavior menu and ask that the property appears in the Inspector pane. It does not seem to work in a window. Is that to be expected?
Windows do not have inspector behaviour in the same way that things like controls do
If you add a property to a class, say a subclass of canvas, and then place instances on your layout then you can set the individual instance properties
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 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.