I have just started with Xojo and come from Ruby on Rails/Filemaker.
Is there any way to automatically find instances or list all instances of a custom class? Lets say, I create “Person” class with the name and age property. Then, I create some instances:
Dim p As New Person ("Peter", 20)
Dim p As New Person ("Christian", 25)
Now I have two instances of “Person”, namely “Peter” and “Christian”. Is there any function like Person.findByName(“Peter”) or Person.ListAll?
Bear in mind that unless you keep a reference to the instances, they will be destroyed when they go out of scope. So you’ve got a property somewhere that’s pointing to them. I’d look that direction first.
You can use a shared property on the class that holds an array of WeakRefs, then use methods to convert to and from the instances. The class Constructor would add itself to the list, and its Destructor removes it. That way you can always get a list of current instances even if they are being retains across many windows, classes, modules, etc.