Ich habe eine generische Klasse TSmartArray, die ein (ebenso generisches) Interface IList implementiert.
Nun habe ich eine Prozedur, deren Signatur einen Parameter vom Typ IList<QWord> definiert. Ich kann dieser Prozedur aber keinen Parameter vom Typ TSmartArray<QWord> übergeben.
Die Klassenstruktur ist ungefähr folgende:
Code: Alles auswählen
{Unit Lists.pas }
generic IList<T> = interface
function GetLow(): Int64;
function GetHigh(): Int64;
function GetLength(): Int64;
function GetElement(Index: Int64): T;
procedure SetElement(Index: Int64; Element: T);
procedure Add(ELement: T);
function GetEnumerator: specialize IListEnumerator<T>;
property Element[Index: Int64]: T read GetElement write SetElement; default;
property Length: Int64 read GetLength;
property Low: Int64 read GetLow;
property High: Int64 read GetHigh;
end;
{Unit SmartArrayList.pas }
generic TSmartArrayList<T> = class(TInterfacedObject, specialize IList<T>)
type
TTArray = array of T;
ITList = specialize IList<T>;
IEnumerator = specialize IListEnumerator<T>;
TEnumerator = specialize TAllListsEnumerator<T>;
public
constructor Create;
constructor Create(AArray: TTArray);
procedure SetLow(ALow: Int64);
function GetLow: Int64;
function GetLength: Int64;
function GetHigh: Int64;
function GetElement(Index: Int64): T;
procedure SetElement(Index: Int64; Element: T);
procedure Add(ELement: T);
procedure AddMany(Elements: ITList);
function GetEnumerator: IEnumerator;
destructor Destroy; override;
property Low: Int64 read GetLow write SetLow;
property Length: Int64 read GetLength;
property High: Int64 read GetHigh;
property Elements[Index: Int64]: T read GetElement write SetElement; default;
{ Die anfängliche Größe des internen Speichers. }
property InitMemLength: Int64 read FInitMemLength write FInitMemLength;
end;
{ Unit primes.pas}
IIntList = specialize IList<QWord>;
TCallback = function(Current: QWord; Len: Int64): Boolean of object;
procedure GenPrimes(List: IIntList; Callback: TCallback);
{ Program reckonprimes.pas }
TQWordList = specialize TSmartArrayList<QWord>;
begin
PrimeList := TQWordList.Create;
Primes.GenPrimes(PrimeList, @CallbackObj.Cllbck); // Und an dieser Stelle kommt der Fehler
end.
Code: Alles auswählen
Free Pascal Compiler version 2.6.4 [2014/03/12] for x86_64
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling genprimes.pas
reckonprimes.pas(40,28) Error: Incompatible type for arg no. 1: Got "TSmartArrayList$QWord", expected "IList$QWord"
Fatal: Compilation aborted
An unhandled exception occurred at $000000000049C313 :
EAccessViolation : Access violation
$000000000049C313
$00000000005430D8
$000000000054763D
$0000000000532959
$000000000052D607
$0000000000453CE8
$000000000056FA34
$000000000042391F
Error: /usr/bin/ppcx64 returned an error exitcode (normal if you did not specify a source file to be compiled)
Theoretisch müsste doch "TSmartArrayList$QWord" "IList$QWord" implementieren. Hab ich einen Denkfehler? Ist das Typsystem von FPC 2.6 noch nicht so weit, sollte ich auf Devlopment-Versionen wechseln?

Ich freue mich auf Antworten,
Joz