Jump to content
Sign in to follow this  
EugeneK

[dcc32 Error] Type parameter 'T' must be a non-nullable value type

Recommended Posts

Hi

 

Anyone else have this error in 12.3

[dcc32 Error] Type parameter 'T' must be a non-nullable value type

Works fine in 12.2, trying to isolate it now, seems to work in some places but not the others.

Share this post


Link to post

Happens when record field has an attribute

unit UTestGenericsBug;

interface

uses
  System.Rtti,
  Data.DB;

type
  DBField = class(TCustomAttribute)
  strict private
    FFieldType: TFieldType;
    FLength: Integer;
  public
    constructor Create(const AFieldType: TFieldType = ftUnknown; const ALength: Integer = 0);
    property FieldType: TFieldType read FFieldType;
    property Length: Integer read FLength;
  end;

  TTestRecord = record
  private
    [DBField(ftString, 20)]
    FTerminalName: string;
  public
  end;

  TRecordLoader<T: record> = class sealed
    class function Get: T; static;
  end;

implementation

constructor DBField.Create(const AFieldType: TFieldType = ftUnknown; const ALength: Integer = 0);
begin

end;

class function TRecordLoader<T>.Get: T;
begin
  Result := Default(T);
end;

function Get: TTestRecord;
begin
  // error here
  Result := TRecordLoader<TTestRecord>.Get;
end;

end.

😒

Share this post


Link to post
TRecordLoader<T> = class sealed
    class function Get: T; static;

If you use full generic declaration it works.

Share this post


Link to post
Just now, DelphiUdIT said:

TRecordLoader<T> = class sealed
    class function Get: T; static;

If you use full generic declaration it works.

Yes I'll probably use it as a workaround, but that kind of defeats the purpose

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×