Einzelnen Beitrag anzeigen

jbg

Registriert seit: 12. Jun 2002
3.481 Beiträge
 
Delphi 10.1 Berlin Professional
 
#16

Re: Error: Inkompatible Typen Reguläre Prozedur u Methodenze

  Alt 31. Aug 2007, 16:16
Zitat von sirius:
Delphi-Quellcode:
  asm //m.code:=@MyListCompare (ging leider nur so)
    push edi
    mov edi, offset MyListCompare
    mov m.code,edi
    pop edi
  end;
Pfui.
m.Code := @TMyList.MyListCompare; Und zum Code "der Schweizer" muss ich sagen: Viel glück unter Systemen mit aktivierter Data Execution Prevention (DEP).


Delphi-Quellcode:
type
  TSortCompareMethod = function(Item1, Item2: Pointer): Integer of object;

procedure MQuickSort(SortList: PPointerList; L, R: Integer;
  SCompare: TSortCompareMethod);
var
  I, J: Integer;
  P, T: Pointer;
begin
  repeat
    I := L;
    J := R;
    P := SortList^[(L + R) shr 1];
    repeat
      while SCompare(SortList^[I], P) < 0 do
        Inc(I);
      while SCompare(SortList^[J], P) > 0 do
        Dec(J);
      if I <= J then
      begin
        if I <> J then // kleine zusätzliche Optimierung
        begin
          T := SortList^[I];
          SortList^[I] := SortList^[J];
          SortList^[J] := T;
        end;
        Inc(I);
        Dec(J);
      end;
    until I > J;
    if L < J then
      MQuickSort(SortList, L, J, SCompare);
    L := I;
  until I >= R;
end;

procedure TMyList.Sort(Compare: TListSortCompareMethod);
begin
  if (FList <> nil) and (Count > 0) then
    MQuickSort(FList, 0, Count - 1, Compare);
end;
  Mit Zitat antworten Zitat