【发布时间】:2016-11-21 14:21:17
【问题描述】:
在以下代码中:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.Generics.Collections;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
TMyClass<T: TForm> = class
public
constructor Create;
end;
var
Form1: TForm1;
List: TDictionary<integer, TMyClass<TForm>>;
implementation
{$R *.dfm}
{ TMyClass<T> }
constructor TMyClass<T>.Create;
begin
List.Add(1, self);
end;
end.
我得到错误:
[dcc32 错误] Unit1.pas(35): E2010 不兼容的类型: 'Unit1.TMyClass' 和 'Unit1.TMyClass.T>'
在我尝试将 Self 添加到 TDictionary 的位置。如何将泛型类添加到 TDictionary,其中第二个参数采用泛型对象?
【问题讨论】:
标签: delphi generics delphi-xe7