program LinkedList; // single linked list { Declarations section } uses MemManager, PascalFunctions; type TMyType = record Content: string[10]; // effective payload of the item //Next: ^TMyType; // recursive definitions not allowed Next: word; // this is the replacement end; var Root, Cursor: ^TMyType; Str: string[10]; procedure AddToList(var S: string[10]); var TmpCursor, TmpPtr: ^TMyType; begin // create an item for the list GetMem(TmpPtr, SizeOf(TMyType)); TmpPtr^.Content := S; // give it its payload TmpPtr^.Next := nill; // link to the next item = nil if Root = 0 then Root := TmpPtr // the Root gets the item if the list was empty else begin // find the end of the list TmpCursor := Root; while TmpCursor^.Next > 0 do TmpCursor := TmpCursor^.Next; // and place the new variable at the end of the list TmpCursor^.Next := TmpPtr; end; // !!! do NOT free TmpPtr, its ram is now part of the linked list end; procedure DisposeList; var TmpCursor: ^TMyType; begin while Root > 0 do begin TmpCursor := Root^.Next; // make the Cursor point to the next item in the list FreeMem(Root, SizeOf(TMyType)); // Dispose of the current item Root := TmpCursor; // and point the Root to the next item end; end; begin { Main program } MM_Init(3000, 1000); // top of heap = 3000, size of heap = 1000; // Creation of the linked list Root := nill; // Adding entries to the list AddToList('Test1'); AddToList('Test2'); AddToList('Test3'); AddToList('Test4'); // Traversing through the list Cursor := Root; while Cursor > 0 do begin Str := Cursor^.Content; // get the payload // do something with Str ... Cursor := Cursor^.Next; // go to next item in the list end; // Get rid of the list (free memory) DisposeList; end.