RAD Studio 10.4.1 is now available! Learn more. Looking for discounts? Visit our Special Offers page!
News

New in 10.2.1: Debug visualisers for Delphi generics

Debug visualisers are a type of IDE plugin that allows you to change the display of a variable in the various debug windows (Local Variables, Watches, Inspector, and Evaluate/Modify.) For example, the TDateTime visualiser takes the double value that represents time and instead displays that time converted to a string. You register a debug visualiser for a type, so all variables of that type, and optionally descendants of that type, go through your visualiser.

In previous versions, this type was specified by a plain string, such as ‘TComponent’, and there was no way to handle a generic type. If you registered ‘MyGeneric<T>’, the visualiser would never be called, because the concrete instantiations of that type do not use T – they might be ‘MyGeneric<Integer>’, ‘MyGeneric<TButton>’, and so forth.

In 10.2.1, we have introduced support for registering a visualiser for a generic type. Your visualizer can implement IOTADebuggerVisualizer250 as well as the prior IOTADebuggerVisualizer, where the GetSupportedType method allows you to specify that the type string is a generic:

 

.
  IOTADebuggerVisualizer250 = interface(IOTADebuggerVisualizer)
    ['{DC0C8D82-B783-4205-B3F4-D325BA8B3EEB}']
    { Return the Index'd Type.  TypeName is the type.  AllDescendants indicates
      whether or not types descending from this type should use this visualizer
      as well. IsGeneric indicates whether this type is a generic type. }
    procedure GetSupportedType(Index: Integer; var TypeName: string;
      var AllDescendants: Boolean; var IsGeneric: Boolean); overload;
  end;

This means you can register for MyGeneric<T> and your visualiser will be called for all MyGeneric<>s. This is all generic types, ie interfaces as well as classes. 

One note is that we do not yet support registering for descendants of a generic type, meaning that if you have MyDesc<T> = class(MyGeneric<T>) or MyDesc = class(MyGeneric<T>), you need to register a visualiser for MyDesc separately. This is because of some complexities in the internal evaluator.

Generics are widely used, especially for collections like dictionaries and lists, and in third-party libraries like Spring4D. We hope you will find visualiser support for generics useful!

Update: here is a code snippet demonstrating a template visualizer


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Deep Dive Webinar: Boost C++Builder Compile Speed with TwineCompile
About author

David is an Australian developer, currently living in far-north Europe. He is the senior product manager for C++ at Idera, looking after C++Builder and Visual Assist.
Related posts
C++

What's New in the GetIt Package Manager - June 2020

C++

RAD Studio 10.4 Now Available, Learn More

C++NewsRAD Studio

Open for Business with 10.4! - May 2020 GM Update

C++DelphiNews

Embarcadero Open Source Project Sponsorship

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES