Inheritance with generics and nested records

I am trying to do the following in Delphi 10.1 Berlin, but the compiler returns the message "Internal error F2084: 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; 

The helper in TMyBaseProcess1 is completely different from the helper in TMyBaseProcess2. I can separate the helper and the class without any problems. I just want to know why I can't leave them together.

Does anyone know what the problem is? Can I use generics, nested helper and inheritance of records this way?

+7
generics inheritance delphi record helper
source share
1 answer

you cannot have two helpers pointing to the same type of class in your TMyType case

from the documentation ..

You can define and associate several helpers with one type. However, in any particular place in the source code, only zero or one is applied.

use helper elements outside these classes

 TMyTypeHelper = record Helper for TMyType public function ToInteger: Integer; function ToString: string; end; 
+1
source share

All Articles