继承泛型和嵌套记录助手
Inheritance with generics and nested record helper
我正在尝试在 Delphi 10.1 Berlin 中执行以下操作,但是编译器 return 消息 "F2084 Internal Error: AV0A785E48-R000000-10-0":
TMyType = (mtValue1, mtValue2);
TMyBaseClass = class
private
FMyType: TMyType;
public
property MyType: TMyType read FMyType write FMyType;
end;
TMyClass = class(TMyBaseClass)
private
FOtherField: Integer;
public
property OtherField: Integer read FOtherField write FOtherField;
end;
TMyBaseProcess1<T: TMyBaseClass> = class
strict private
FMyClass: T;
strict protected
type
TMyTypeHelper = record Helper for TMyType
public
function ToString: string;
end;
public
constructor Create(AMyClass: T);
procedure DoSomething;
end;
TMyProcess1 = class(TMyBaseProcess1<TMyClass>)
end;
TMyBaseProcess2<T: TMyBaseClass> = class
strict private
FMyClass: T;
strict protected
type
TMyTypeHelper = record Helper for TMyType
public
function ToInteger: Integer;
end;
public
constructor Create(AMyClass: T);
procedure DoSomethingElse;
end;
TMyProcess2 = class(TMyBaseProcess2<TMyClass>)
end;
TMyBaseProcess1 中的helper 与TMyBaseProcess2 中的helper 完全不同。我可以毫无问题地将助手和 class 分开。我只想知道为什么我不能把他们留在一起。
有人知道问题出在哪里吗?我可以这样使用泛型、嵌套记录助手和继承吗?
你不能有 两个 助手指向相同的 class 类型
在你的情况下 TMyType
来自文档..
You can define and associate multiple helpers with a single type. However, only zero or one helper applies in any specific location in source code.
在 classes
之外使用 helper
TMyTypeHelper = record Helper for TMyType
public
function ToInteger: Integer;
function ToString: string;
end;
我正在尝试在 Delphi 10.1 Berlin 中执行以下操作,但是编译器 return 消息 "F2084 Internal Error: AV0A785E48-R000000-10-0":
TMyType = (mtValue1, mtValue2);
TMyBaseClass = class
private
FMyType: TMyType;
public
property MyType: TMyType read FMyType write FMyType;
end;
TMyClass = class(TMyBaseClass)
private
FOtherField: Integer;
public
property OtherField: Integer read FOtherField write FOtherField;
end;
TMyBaseProcess1<T: TMyBaseClass> = class
strict private
FMyClass: T;
strict protected
type
TMyTypeHelper = record Helper for TMyType
public
function ToString: string;
end;
public
constructor Create(AMyClass: T);
procedure DoSomething;
end;
TMyProcess1 = class(TMyBaseProcess1<TMyClass>)
end;
TMyBaseProcess2<T: TMyBaseClass> = class
strict private
FMyClass: T;
strict protected
type
TMyTypeHelper = record Helper for TMyType
public
function ToInteger: Integer;
end;
public
constructor Create(AMyClass: T);
procedure DoSomethingElse;
end;
TMyProcess2 = class(TMyBaseProcess2<TMyClass>)
end;
TMyBaseProcess1 中的helper 与TMyBaseProcess2 中的helper 完全不同。我可以毫无问题地将助手和 class 分开。我只想知道为什么我不能把他们留在一起。
有人知道问题出在哪里吗?我可以这样使用泛型、嵌套记录助手和继承吗?
你不能有 两个 助手指向相同的 class 类型 在你的情况下 TMyType
来自文档..
You can define and associate multiple helpers with a single type. However, only zero or one helper applies in any specific location in source code.
在 classes
之外使用 helperTMyTypeHelper = record Helper for TMyType
public
function ToInteger: Integer;
function ToString: string;
end;