Thema: Delphi TObjectList Sortieren

Einzelnen Beitrag anzeigen

franktron

Registriert seit: 11. Nov 2003
Ort: Oldenburg
1.446 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#1

TObjectList Sortieren

  Alt 1. Mär 2019, 16:17
Ich habe ein Problem beim Sortieren einer Klasse

Delphi-Quellcode:
  TAnfrage_Sort = class(TComparer<TAnfrageItem>)
    function Compare(Const Left,Right : TAnfrageItem): Integer; override;
  end;
  TAnfrageItem = class
  private
    function GetSortInt: LongInt;
    .....
  public
    property ID : LongInt read FID write SetID;
    property TypID : Longint read FTypID write SetTypID;
    property Bemerkung : TStringList read FBemerkung write SetBemerkung;
    property isJa : Boolean read FisJa write SetisJa;
    property Text : String read FText write SetText;
    property Farbe : TAlphaColor read FFarbe write SetFarbe;
    property GruppeID : Longint read FGruppeID write SetGruppeID;
    property Sort : Longint read FSort write SetSort;
    property SortGruppe : Longint read FSortGruppe write SetSortGruppe;
    property SortInt : LongInt read GetSortInt;

    constructor Create;
    destructor Destroy; override;
  end;
  
function TAnfrageItem.GetSortInt: LongInt;
begin
  Result:=StrToInt(FormatFloat('0000',FSortGruppe)+FormatFloat('0000',FSort));
end;


Function TAnfrage_Sort.Compare(const Left,
  Right: TAnfrageItem): Integer;
var
  i : Integer;
begin
  i:=0;
  if Left.SortInt>Right.SortInt then
  begin
    i:=1;
  end;
  if Left.SortInt<Right.SortInt then
  begin
    i:=-1;
  end;
  Result:=i;
end;

Hier der Aufruf
procedure TAnfrage.Sort;
var
  LPC : IComparer<TAnfrageItem>;
begin
  LPC:=TAnfrage_Sort.Create;
  FItems.Sort(LPC);
end;
Ich will 2 Felder Sortieren also SortGruppe,Sort
aber irgendwie klappt das Sortieren gar nicht es kommt nur Blödsinn raus.

SortGruppe ist immer richtig Sort leider nicht.

Was mache ich da Falsch
Frank
Tux sein Lieblingsquellcode
While anzfische<TuxSatt do begin
Fisch:=TFisch.Create; Tux.EssenFisch(Fisch); Fisch.Free;inc(anzfische); end;
  Mit Zitat antworten Zitat