Universal Debug Visualizer for Delphi

As mentioned in my previous post on dzDebugVisualizer I was thinking about writing a generalized debug visualizer which can be user-configured to register itself for any data type. Well, that debug visualizer now exists. It’s part of dzDebugVisualizer and called “Universal Visualizer for Delphi”.

It has got a configuration page in the Tools -> Options dialog where the user can configure the types that visualizer should handle and how it should handle them.

The screnshot shows the types and expressions to be evaluated for each type that will be added to the list when pressing “Add Defaults”. As you can see all these types are advanced records and they are visualized by simply passing their Dump method to the debugger. I described how this works in my previous post. Note that for this to work, the Dump method must be available, so the linker must not remove it. How this can be achieved, is also described there. This is how it works for TNullableGuid.

(Click on the screenshot to show it in fulls size.)

As you can see, the values of the fields are still available for inspection, if you need them.

Calling a Dump method is not the only option to visualize a type. Any function that converts the value to a human readable format can be used, e.g. TColor could be visualized by calling ColorToString, by adding

Type Expression to evaluate
TColor ColorToString({Expression})

Unfortunately this is more likely to fail if the program does not already use that function and the unit that provides it (Vcl.Graphics or Fmx.Graphics) is not in the uses clause of the current unit.

The implementation is far from rocket science. The user could simply add a watch with the same function/method call, e.g. MyNullableDate.Dump instead of only MyNullableDate or ColorToString(MyColor) instead of only MyColor and allow function calls and side effects. The debug visualizer only adds convenience because it automatically adds the function/method call and also works in the Local Variables window and the value hints.

The source code is still available on SourceForge. It contains Packages for Delphi 10.2 and 12, but packages for other versions should be easy to create.

Edit 2024-07-01:
I should have mentioned that the caveat from my previous post still applies:

Calling a method from a debug visualizer is slow. If there are multiple types, e.g. in the Local Variables debug window, there is a noticeable delay every time that window is refreshed. At least on my computer.
Unfortunately there isn’t much that can be done about the slowdown of the debugging display. It is caused by the evaluator calling the Dump method in the debugged executable, waiting for the function to return and then passing the result back to the debug visualizer. The only way to avoid this would be to move the code from the Dump method into the debug visualizer.

Discussion about this post in the international Delphi Praxis forum.