for i := 0 to PtCount - 1 do
begin
for j := 0 to PtCount-i - 2 do
begin
TempP:=Pts[j];
if Pts[j].Y < Pts[j+1].Y then
begin
Pts[j]:= Pts[j+1];
Pts[j+1]:= TempP;
end;
end;
end;