Ok first, thx for the answers, brought me much further!
second:
* I have to ask, why is it not allowed to have only 1 definition of "PNode = ^specialize TNode<T>" in a global type
section, like within an "interface"-section? why must I have it written in each record/class -type section?
I understand partly, that the "<T>" is needed somehow to say its a pointer of a TNode<T> and the<T>is not
known otherwise, but cant you guys make it possible, to write only this and still make the compiler understand
that: <"declare a pointer to a TNode, even without now knowing what "T" is, so whatever the specialization of
"T" will be, I just want to have a pointer type of that type">
I hope I could my suggestion/question formulate properly and understandably ^^
It is not possible to have a general
PNode as the compiler needs to know the size of the right side so that
Inc or array access work correctly.
What would technically be possible would be what you had suggested earlier with
generic PNode<T> = ^specialize TNode<T>, but it would not safe anything:
type
generic TNode<T> = record
end;
generic PNode<T> = ^specialize TNode<T>;
generic TSomething<T> = record
function CreateNode: specialize PNode<T>;
end;
You see the declaration of
CreateNode? To avoid having to type that out I'd have to do this anyway:
generic TSomething<T> = record
public type
MyPNode = specialize PNode<T>;
public
function CreateNode: MyPNode;
end;
So there is no real difference between the existing solution and your proposed on except one single
^.
Also records can only be forward declared for the use in pointers (which would be the case here), but for generics that provides a whole new box of potential problems. (There is a bug report to allow forward declarations of generic classes for Delphi compatibility, but that needs to be handled with care as well)