Hmm...I obviously hadn't thought this through. ;o)
This okay?
This okay?
Strict Type TBase Field link:TLink Method AddFirst(list:TList) ' Just for consistency link = list.AddFirst(Self) End Method Method AddBefore(obj:TBase, list:TList) link = list.InsertBeforeLink(Self, obj.link) End Method Method AddAfter(obj:TBase, list:TList) link = list.InsertAfterLink(Self, obj.link) End Method Method AddLast(list:TList) ' Just for consistency link = list.AddLast(Self) End Method Method First:Object(list:TList) ' Just for consistency Return list.First() End Method Method After:Object() If link.NextLink() Then Return link.NextLink().Value() End Method Method Before:Object() If link.PrevLink() Then Return link.PrevLink().Value() End Method Method Last:Object(list:TList) ' Just for consistency Return list.Last() End Method Method Remove() If link Then link.Remove() End Method Function RebuildLinks(list:TList) ' All object in list must be derived from TBase (or add a check) Local thisLink:TLink = list.FirstLink() While thisLink TBase(thisLink.Value()).link = thisLink thisLink:TLink = thisLink.NextLink() Wend 'Flushmem End Function End Type Type TTest Extends TBase Field id:String End Type Local testList:TList = New TList Local a:TTest = New TTest a.id = "a" a.AddLast(testList) Local b:TTest = New TTest b.id = "b" b.AddBefore(a, testList) Local c:TTest = New TTest c.id = "c" c.AddFirst(testList) For Local t:TTest = EachIn testList Print t.id Next testList.Reverse() 'You need to rebuild the links whenever the lists are re-ordered externally. TBase.RebuildLinks(testList) 'TTest.RebuildLinks(testList) if you prefer Print For Local t:TTest = EachIn testList Print t.id Next Print Print TTest(a.After()).id