![]() |
TObjectList Sortieren
Ich habe ein Problem beim Sortieren einer Klasse
Delphi-Quellcode:
Ich will 2 Felder Sortieren also SortGruppe,Sort
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; 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 |
AW: TObjectList Sortieren
Debuggen?
|
AW: TObjectList Sortieren
Also entweder multiplizieren oder Du sortierst den String.
Delphi-Quellcode:
function TAnfrageItem.GetSortInt: LongInt;
begin Result:=StrToInt(FormatFloat('0000',FSortGruppe)*10000+FormatFloat('0000',FSort)); end; |
AW: TObjectList Sortieren
Warum so kompliziert mit SortInt?
Delphi-Quellcode:
Das CompareValue findest du in System.Math.
function TAnfrage_Sort.Compare(const Left, Right: TAnfrageItem): Integer;
begin Result := CompareValue(Left.SortGruppe, Right.SortGruppe); if Result = 0 then Result := CompareValue(Left.Sort, Right.Sort); end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:44 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz