How to implement generic TListNode? lazarus / 21-General ---------------------------------------------------------------------- Kyun · 2025-05-10 03:55 I attempted to learn data structures using Pascal, but soon ran into problems. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  generic TListNode = record    Value: T;    Prev: TListNode; // error    Next: TListNode; // error  end;  I don't know what kind of grammar to use here. ---------------------------------------------------------------------- ALLIGATOR · 2025-05-10 04:10 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   generic TListNode = record    Value: T;    Prev: Pointer;    Next: Pointer;  end; or Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program app;{$modeswitch advancedrecords} type  generic TListNode = record  type    TSelf = specialize TListNode;    PSelf = ^TSelf;  public  Value: T;    Prev: PSelf;    Next: PSelf;  end; ---------------------------------------------------------------------- TRon · 2025-05-10 04:25 Quote from: Kyun on May 10, 2025, 05:55:34 ambut soon ran into problems. ALLIGATOR showed possible solutions. Reason you got stuck is described here which basically tells that it is not possible to forward types (unless using a pointer to the type). ---------------------------------------------------------------------- Thaddy · 2025-05-10 06:34 Yes. Prefer the second example over the typeless pointer, though. The reason that it is the correct way, using a typed pointer,  is that when you would use a record type itself you will get an endless loop if the compiler would not prevent it. And an untyped pointer is almost never a good idea. Using a record itself would expand into infinity..... (Think!) ---------------------------------------------------------------------- Kyun · 2025-05-10 14:52 Quote from: ALLIGATOR on May 10, 2025, 06:10:44 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   generic TListNode = record    Value: T;    Prev: Pointer;    Next: Pointer;  end; or Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program app;{$modeswitch advancedrecords} type  generic TListNode = record  type    TSelf = specialize TListNode;    PSelf = ^TSelf;  public  Value: T;    Prev: PSelf;    Next: PSelf;  end;  Thanks, Pointer like C++'s void* ---------------------------------------------------------------------- Kyun · 2025-05-10 14:53 Quote from: TRon on May 10, 2025, 06:25:48 amQuote from: Kyun on May 10, 2025, 05:55:34 ambut soon ran into problems. ALLIGATOR showed possible solutions. Reason you got stuck is described here which basically tells that it is not possible to forward types (unless using a pointer to the type). Thank you, this document is very useful.