Debug visualizers for my TNullable types

My dzlib contains several nullable data types which internally use an interface field to maintain the IsValid value as originally suggested by Alan Bauer in a post on his long defunct Codegear blog “The Oracle at Delphi” (links to the Internet Archive).

Today I added debug vizualizers for these types to my dzDebugVisualizer package.
Rather than showing the two fields FIsValid and FValue …

… the debugger now shows either <invalid> or the actual value of the type.

This works for the Watch List, the Local Variables and the Evaluate and Modify windows as well as the value hints you get when holding the mouse over a variable in the source code.

Some notes, mostly for my future self:

  • You cannot register a debug visualizer for a type that’s simply an alias for another type, e.g.
    type
      TSomeNewType = TSomeExistingType
  • You can register a debug visualizer for a strong aliased type, e.g.
    type
      TSomeNewType = type TSomeExistingType
  • The value hints for a record contain the field names and their values
    (Field1:Value1; Field2:Value2)

    rather than just the values as in the debugger windows

    (Value1, Value2)

    And since that’s the string passed to the debug visualizer the code must handle both formats.