How does the method Sort of the class TList work? Does this method only sort in a way that the elements of the list only ascend/descend? Please, have a look at the code below.
Type
PInteger = ^Integer;
Function Compare(Item1, Item2 : Pointer) : Integer;
Begin
if PInteger(Item1)^ > Pinteger(Item2)^ then Result:= 1
else if PInteger(Item1)^ < PInteger(Item2)^ then Result:= -1
else Result:= 0;
End;
{ And, for instance, somewhere we call the method }
List.Sort(Compare);
Now the thing is, after i compile the code, it works well, the list is sorted in a way that the elements ascend. But i don't understand the following line:
PInteger(item1)^ // What does this represent?
And what item1, item2 pointers point to? Do they not need to be initialized?
delphitag alone.PInteger(item1)^casts the pointeritem1to a typed pointer (i.e PInteger) then dereference it (i.e use the value stored in the addressitem1).