Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a type alias to a generic record in Delphi [duplicate]

I would like to define a record type (type alias) for a generic record. I would like to do this so users of unit b can have access to TMyGenericRecord without using unit a. I have units like this:

unit a;
interface
type
  TMyNormalRecord = record
    Item: Integer;
  end;
  TMyGenericRecord<T> = record
    Item: T;
  end;
implementation
end.

unit b;
interface
type
  TMyNormalRecord = a.TMyNormalRecord;  // works
  TMyGenericRecord<T> = a.TMyGenericRecord<T>; // E2508 type parameters not allowed on this type
implementation
end.
like image 741
Daniel Andrascik Avatar asked Apr 22 '13 14:04

Daniel Andrascik


1 Answers

The simple answer to the question is that the language does not support generic type aliases.

The only places where you can use generic parameters are:

  1. Generic class, interface, record and array types, or
  2. Generic procedural types, or
  3. Generic methods.
like image 116
David Heffernan Avatar answered Nov 03 '22 08:11

David Heffernan