Well, the sorting is beyond me, but not the swappage of pointers. That's really simple once you figure it out. Here's the gist:
Code:
procedure SwapPointers(var p1,p2: Pointer);
var
   tmp: pointer;
begin
  tmp := p1;
  p1  := p2;
  p2  := tmp;
end;
It really is that simple. If it complains about the pointer type or anything, just typecast it into a pointer when you pass it.