AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

TObjectList Sortieren

Ein Thema von franktron · begonnen am 1. Mär 2019 · letzter Beitrag vom 1. Mär 2019
Antwort Antwort
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
freimatz

Registriert seit: 20. Mai 2010
1.384 Beiträge
 
Delphi 11 Alexandria
 
#2

AW: TObjectList Sortieren

  Alt 1. Mär 2019, 16:18
Debuggen?
  Mit Zitat antworten Zitat
Benutzerbild von Union
Union

Registriert seit: 18. Mär 2004
Ort: Luxembourg
3.487 Beiträge
 
Delphi 7 Enterprise
 
#3

AW: TObjectList Sortieren

  Alt 1. Mär 2019, 16:22
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;
Ibi fas ubi proxima merces
sudo /Developer/Library/uninstall-devtools --mode=all
  Mit Zitat antworten Zitat
Benutzerbild von Uwe Raabe
Uwe Raabe

Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.021 Beiträge
 
Delphi 12 Athens
 
#4

AW: TObjectList Sortieren

  Alt 1. Mär 2019, 16:57
Warum so kompliziert mit SortInt?
Delphi-Quellcode:
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;
Das CompareValue findest du in System.Math.
Uwe Raabe
Certified Delphi Master Developer
Embarcadero MVP
Blog: The Art of Delphi Programming
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:01 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz