【问题标题】:Why does the declaration of a TDictionary with a type as key throw an internal L2095 error?为什么以类型为键的 TDictionary 声明会引发内部 L2095 错误?
【发布时间】:2017-04-26 13:14:39
【问题描述】:

有人知道为什么下面的代码会引发内部 L2095 错误吗?

显然编译器有问题,字典的键是类类型。

有人知道解决方法吗?

(PS:当我不包含TestDict := TDictTest.Create; 部分或键不是类类型时,不会引发错误)

  TTestClass = class
  end;

  TTypeOfTestClass = type of TTestClass;

  TDictTest = TDictionary<TTypeOfTestClass,Integer>;

var
  TestDict: TDictTest;

implementation

initialization

  TestDict := TDictTest.Create;
  TestDict.Free

回答后添加

显然这是关于我本能地使用“type of”而不是“class of”。 “Type of”被编译器接受,因此会造成混淆。 引用与此相关的问题:What "type of" declaration represents in Delphi and how can it be used

【问题讨论】:

    标签: delphi generics delphi-xe2


    【解决方案1】:

    我认为甚至不允许使用“...的类型”。使用

    TTypeOfTestClass = class of TTestClass;
    

    改为。

    【讨论】:

    • 我确实应该使用“class of”!我在代码的其他部分这样做,但由于某种原因,这次我使用了“type of”并且它确实编译了,这很奇怪。除了 TDictionary 声明之外,它似乎在任何地方都被接受。奇怪的。不过谢谢!
    猜你喜欢
    • 1970-01-01
    • 2017-02-14
    • 1970-01-01
    • 2014-05-07
    • 2016-09-30
    • 2018-03-30
    • 1970-01-01
    • 2011-01-19
    • 1970-01-01
    相关资源
    最近更新 更多