Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inheritance with generics and nested record helper

I'm trying to do the following in Delphi 10.1 Berlin, but the compiler return the message "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;

The helper in TMyBaseProcess1 is totally different of the helper in TMyBaseProcess2. I can separate the helper and the class without problems. I only want to know why I can't leave them together.

Anyone knows what is the problem? Can I use generics, nested record helper and inheritance this way?

like image 514
Lucas Felipe Silva Avatar asked Mar 01 '17 18:03

Lucas Felipe Silva


1 Answers

you can not have two helpers pointing to same class type in your case TMyType

from docs..

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.

use helper outside that classes

TMyTypeHelper = record Helper for TMyType
    public
      function ToInteger: Integer;
      function ToString: string; 
    end;
like image 193
Livius Avatar answered Sep 28 '22 07:09

Livius