Printing entire object as string?

Hi all, still getting started with Xojo, so not sure if this is possible: does Xojo have a way to print out an entire object and its properties as a string, without creating my own method to do it? I want to make a listbox that acts like the Xojo debugger’s variable window - showing type, value, etc - all without having to manually code in every property in the code. If not, I assume I could serialize the object to JSON and then attach the JSON string to the listbox. I found this code on the forums:

  dim props() as Introspection.PropertyInfo = Introspection.GetType(val).GetProperties()
  for each p as Introspection.PropertyInfo in props
    
    // add p.Name to a listbox...
    
  next

But obviously not all methods have a String method if I try to find out the values to the list box using str(p.Value).

Thanks!

i remember there is no object serialization (like in C#).

somehow this list the first level of object properties.

ListObjects(Array(New Class1),ListBox1)

Public Sub ListObjects(objs() as Object, li as DesktopListBox)
  li.RemoveAllRows
  
  For Each o As Object In objs
    Var ti As Introspection.TypeInfo
    ti = Introspection.GetType(o)
    li.AddRow(ti.FullName)
    Dim props() As Introspection.PropertyInfo = ti.GetProperties()
    For Each pi As Introspection.PropertyInfo In props
      Var x As Variant = pi.Value(o)
      If pi.PropertyType.IsClass Then
        li.AddRow Array(pi.Name, Introspection.GetType(x).FullName) 'Class
      Else
        li.AddRow Array(pi.Name, x)
      End If
    Next
  Next
    
End Sub

there is a example in

\Example Projects\Framework\IntrospectionExample.xojo_binary_project

1 Like

Thank you!

1 Like