Skip to content

Introspection

Introspection is a very handy and useful part of the Xojo language.

You can use it to examine a lot of the objects that are in memory at runtime. You can access the properties in those objects, call methods on those objects and even create new instances (with some caveats here).

But there are limits to what you can do with it. You can’t use it to create things that do not exist at runtime because they’ve been stripped out when your app was built.

Suppose you have a class, MyCoolClass, and nowhere in your app do you have a parameter of that type used, a property of that type, or you never have any IsA MyCoolClass checks and never dim a variable as MyCoolClass. Then the likelihood your class has been stripped out of the final built executable is high. Basically if you never use the class it will likely get stripped out.

It’s possible to create classes that exist at runtime so you have to make sure they do not get stripped out. And there is no way for you to create one at runtime “by name” because there is no “make me this class by name” operator or function.

So in order to use introspection to create a class you need to have the class IN your compiled code.

Something like:

dim ti as Introspection.TypeInfo = GetTypeInfo( MyCoolClass )

will ensure MyCoolClass won’t be stripped out. And then you can creates instances from the TypeInfo by accessing the class’ constructors.

Watch our Intro to Introspection webinar on-demand:


Introduction to Introspection