On 9 May 2016 at 12:48, Richard Mace <richard.m...@gmail.com> wrote: > I have a TObjectList that contains many objects that have a property > called "Position" which is an integer. > > Could somebody show me an example of the code that I will need to create > that will sort all of my Objects within the TObjectList so that they are in > position order e.g. 1,2,3,4,5 and so on? >
Call TList.Sort method and supply a comparison function. For example: List.Sort(@CompareByPositionPtr); function CompareByPosition(A, B: TMyObject): Integer; inline; begin if A.Position < B.Position then Result := -1 else if A.Position > B.Position then Result := 1 else Result := 0; end; function CompareByPositionPtr(A, B: Pointer): Integer; begin Result := CompareByPosition(TMyObject(A), TMyObject(B)); end; This kind of question is better suited on the forum I think Denis
-- _______________________________________________ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus