Have a property in your class or declare a variable in code for storing the window reference into a variable.
So for example, something like this (either in code or added through a property of the class (depends on wether it is to be used after the execution of the constructor).
Then create a method called ‘Constructor’, this will be executed when a new instance of the class is made. This will also allow you to pass in some parameters.
Have a parameter in the constructor as something like ‘win as window’ or ‘win as myWindow’ (if myWindow subclasses window).
Then code into the method something to method something like ‘theWindow = win’. That is if you declare theWindow as a property of the class.
If you want to refer to the window from just the constructor, refer the window using ‘win’, as it is declared as parameter of the constructor or you can reference theWindow (outside and inside the constructor).
I’ll put this out in code for you to make it easier to understand:
//reference the window on the same line as creating an instance of myClass
dim myObject as new myClass(self)
class myClass
//class property (not declared in code)
dim theWindow as window
sub constructor(win as window)
theWindow = win
end sub
sub closeWindowForThisClass()
theWindow.close()
end sub
end class
Probably confusing but you can ask me any questions if you wish. I wrote ‘dim theWindow as window’ as pseudo code representing the declaring of a variable as a property instead of through code if that makes sense.
BTW - If you are interested in learning more about the power of event definitions within Xojo, the definitive book on the subject is linked here (from another topic, link provided by Norman Palardy) http://relevantlogic.com/oop-book/about-the-oop-book.php
Use a class interface. Define methods that tell the window to update themself with this information. That way, your class doesn’t need to know the details, it just throws the data at the window and lets the window do whatever is appropriate.
The window implements the class interface. you pass a parameter of type your-class-interface to be object instance. The object calls the methods in the class interface and passes its data to them. any window that implements the interface can be passed to the object and it doesn’t need to know the details of the window.