Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Code snippet: IDE debug visualizer plugin for generic and template types

In RAD Studio 10.2.1 we added support for debug visualizers for Delphi generic and C++ template types.  A debug visualizer is an IDE plugin that allows you to change the display of a variable in the various debug windows, such as Local Variables and Watches.

“Great!”, you may think, “but how do I actually write one of these visualizers?”

Pretty easily, as it turns out.

A debug vizualiser is an interfaced class that implements some specific Open Tools API interfaces (see toolsapi.pas), located in a DLL or package, and an instance of which is registered with the IDE when the package is loaded.  Those interfaces are:

Generic and template debug visualizer example

Here’s a complete visualizer code snippet.  To test this out, create a new package, and add designide to the Requires. Then add a unit called GenericVisualizer.pas to it and paste in the following source code.  To test it out, just right-click and Install, and then it’s running right there inside your local IDE instance.  (You can also debug the IDE with IDE if you want to do some more advanced work and load it while debugging an instance of the IDE with your first copy of the IDE.)

Source code

[crayon-67682f62de176571608939/]

 

To test

For Delphi

Define some types:

[crayon-67682f62de17c025690068/]

This example is longer than the C++ one, because it demonstrates both generic classes and interfaces.  It also shows some descendant types, where you need to register the descendant type separately. (For a non-generic-type debug visualizer, the visualizer is called for descendants of the registered type automatically.)

And create a new console app, giving it the contents:

[crayon-67682f62de17e696233862/]

For C++

Create a new console app (and some shiny new template types as well, if you wish) and give it the contents:

[crayon-67682f62de17f139986429/]

To extend

This is the exciting bit!  Try changing the data returned from GetReplacementValue(), and also try evaluating expressions yourself in the visualizer to use in the returned replacement.

Have fun!

 

Exit mobile version