Introspection? (newbie to this)

Hello everyone,

Excuse what is probably the ‘dumb question of the day’ but I need your wisdom! (I have been trying to do this myself, using searches on here to help, sadly, I’m beaten!).

I need a way to iterate through properties on a window to see if one with a given name exists, and, if it does, what it’s value is (it’s a string).

Please save a grown man in distress.

Regards,
Dave.

Since you’ve mentioned that you’re a newbie - let’s start with the proposition that Introspection, while useful in some cases, should be the tool of last resort. There are usually better (and more easily understood) ways of doing things in Xojo.

With that in mind, why don’t you tell us a little more about what you are trying to accomplish and perhaps we can offer you a better suggestion?

4 Likes

https://documentation.xojo.com/topics/advanced_features/inspecting_your_application_structure_from_code_with_introspection.html#inspecting-your-application-structure-from-code-with-introspection

maybe u need IsA
https://documentation.xojo.com/api/language/isa.html#isa

or some useful thing is an Interface assigned to a Window.
https://documentation.xojo.com/getting_started/object-oriented_programming/interfaces.html

This might help you

var w as DesktopWindow = self //Pointer to class to inspect

var info as Introspection.TypeInfo = Introspection.GetType(w)
if info = nil then 
  System.DebugLog("Odd")
  return
end if

var props() as Introspection.PropertyInfo = info.GetProperties

//loop through all properties attached
for each p as Introspection.PropertyInfo in props
  
  //look for Strings
  if p.PropertyType.Name.Lowercase = "string" then
    
    //Found a string
    system.DebugLog("Found String """ + p.Name + """ with value """ + p.Value(w).StringValue) + """"

    
  end if
  
next p
1 Like

100% agree with Eric. What are you really trying to achieve? An interface and ISA may be a much better approach.

if Window1 ISA MyInterface then
   x = MyInterface(Window1).GetTheValue
end
2 Likes

Not to mention, faster.

2 Likes

Thanks man! Really appreciate you taking the time to do that. All the best, Dave.