8.7 Using the default intrinsic

When writing generic routines, sometimes a variable must be initialized whose type is not known during the declaration of the generic. This is where the Default intrinsic (section 4.5, page 261) also comes into play. Given the following generic declaration:

type
  generic TTest<T> = class
    procedure Test;
  end;

The following code will correctly initialize the variable myt during specialization:

procedure TTest.Test;
var
  myt: T;
begin
  // will have the correct Default if class is specialized
  myt := Default(T);
end;