1
添加以下代碼:德爾福(XE7)泛型類通用TDictionary
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 Error] Unit1.pas(35): E2010 Incompatible types: 'Unit1.TMyClass' and 'Unit1.TMyClass.T>'
在那裏我試圖自我添加到TDictionary。我如何將泛型類添加到TDictionary中,其中第二個參數需要通用對象?
謝謝。滑稽:變量「列表」必須在界面內,而不是執行。 – Makla