Niepoprawne działanie Quick Sort

Nie działa mi quick sort który wg mnie powinien działać,

nie widzę gdzie się kropnąłem, może ktoś zauważy.

TPair=packed record Id,Value:Int64; end;TPairArray=array of TPair; [/code]

[code=php]procedure SortPairByValueId(var List:TPairArray);procedure Sort(L,H:Integer);pL,pH,M:Integer;T:TPair;Cmp(P:Integer):Integer;beginif List[P].ValueM].Value then Result:=-1else if List[P].ValueList[M].Value then Result:=1else if List[P].IdM].Id then Result:=-1else if List[P].IdList[M].Id then Result:=1else Result:=0;end;begin:=L;pH:=H;M:=(pL+pH)shr(1);repeatwhile Cmp(pL)0 do Inc(pL);Cmp(pH)0 do Dec(pH);pL=pH then