FoxPro Programming
Recursively collecting object hierarchy into a string or cursor
Gravatar is a globally recognized avatar based on your email address. Recursively collecting object hierarchy into a string or cursor
  Michael Hogan (Ideate Hosting)
  All
  Mar 9, 2021 @ 02:28pm

I need to diagnose some object hierarchy issues in a webconnect project

Does anyone have some neat code to recursively go through an object and write out the property names and values to something I can review?

Gravatar is a globally recognized avatar based on your email address. re: Recursively collecting object hierarchy into a string or cursor
  Mike McDonald
  Michael Hogan (Ideate Hosting)
  Mar 9, 2021 @ 07:04pm

Michael -

In wwUtils, there is a PropertyDump() function which will write out the key/value pairs for a single object, although that function is not recursive.

However, the wwUtils::CopyObject() function is recursive. You should be able to combine & adapt the two functions to get exactly what you want.

- Mike McDonald
Software Design of Kentucky

Gravatar is a globally recognized avatar based on your email address. re: Recursively collecting object hierarchy into a string or cursor
  Michael Hogan (Ideate Hosting)
  Mike McDonald
  Mar 9, 2021 @ 07:15pm

Nice! Thanks a ton, Mike.

Gravatar is a globally recognized avatar based on your email address. re: Recursively collecting object hierarchy into a string or cursor
  Rick Strahl
  Michael Hogan (Ideate Hosting)
  Mar 10, 2021 @ 01:41pm

I use JSON serialization for this.

DO wwJsonSerializer
_clipText = JsonSerialize(loObject, .T.)  && formatted

Then open in VS Code or other JSON capable editor.

It'll do the hierarchy. You can get into the weeds with nested object references though so careful with that.

--- edit ---

Come to think about it you can use ShowText() to display the JSON too:

DO wwJsonSerializer
DO wwUtils
lcJson = JsonSerialize(loObject, .T.)  && formatted
ShowText(lcJson,"c:\temp\output.json")  && opens in configured editor (VS Code for me)

+++ Rick ---

© 1996-2024