Add the LibLinkList unit to your USES clause.
Declare node object class as descendant of TListNode:
TYPE TMyNode = CLASS (TListNode) field1 : STRING ; field2 : INTEGER; ... END;
Create an instance of your list:
VAR MyList : TLinkList; BEGIN ... MyList := TLinkList.Create; ...
MyNode := TMyNode.Create (...); MyList.Append (MyNode);
MyList.InsertFirst (MyNode); // Inserts MyNode as first node of list
MyList.Insert (Node, MyNode); // Inserts MyNode after Node
Declare scan pointer variable:
VAR CurNode : TMyNode;
MyList.StartScan (CurNode); WHILE MyList.Scan (CurNode) DO BEGIN CurNode.DoSomething; ... END;
NOTE: You must not delete the current node. If you want to delete nodes while scanning through the list, you need to hop from node to node for yourself.
LblCount.Caption := IntToStr (MyList.Count);
VAR NodeToDelete : TMyNode; BEGIN ... NodeToDelete := MyList.At (1); // Node "1" is the second node because "At" expects the argument to be a zero-based index ... MyList.Delete (NodeToDelete);
Extracts NodeToDelete from the list and destroys it.
Use Extract instead of Delete if you don't want to destroy the node object.
This will also delete and destroy all remaining nodes from the list.