Find instance / List all instances possible?

Hey guys,

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?


You can use runtime module:

And do an isa on each object and add those you want to the array.

Thanks, what is an “isa”?

[quote=295090:@Christian Schmitz]You can use runtime module:

And do an isa on each object and add those you want to the array.[/quote]

How can I access each property / method of the iterated objects ? A label for example ?

On a form I have:

[code] break

dim a() as Auto

Dim o as Runtime.ObjectIterator=Runtime.IterateObjects
While o.MoveNext
if o.Current isa Customlabel then
a.append Introspection.GetType(o.Current)

 end if



Dim c as CustomLabel = CustomLabel(o.current)

And than use c

Of course… Thanks Christian.

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.