AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Sortierte TObjectList - Einträge richtig einfügen
Thema durchsuchen
Ansicht
Themen-Optionen

Sortierte TObjectList - Einträge richtig einfügen

Ein Thema von Benmik · begonnen am 17. Jul 2015 · letzter Beitrag vom 24. Sep 2015
 
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#34

AW: Sortierte TObjectList - Einträge richtig einfügen

  Alt 21. Sep 2015, 12:49
Doch geht schon
Delphi-Quellcode:
unit Unit1;

interface

uses
  Generics.Collections,
  Generics.Defaults;

type
  TLogFile = class
  private
    FFileId : Integer;
    FFileName: string;
  public
    property FileId : Integer read FFileId;
    property FileName: string read FFileName;
  public
    class function IdentityCompare( const L, R: TLogFile ): Integer; static;
    class function NameCompare( const L, R: TLogFile ): Integer; static;
  end;

  TLogFileList = class( TObjectList<TLogFile> )
  public
    constructor Create( AOwnsObjects: Boolean = True );
  end;

implementation

{ TLogFile }

class function TLogFile.IdentityCompare( const L, R: TLogFile ): Integer;
begin
  Result := TComparer<Integer>.default.Compare( L.FFileId, R.FFileId );
end;

class function TLogFile.NameCompare( const L, R: TLogFile ): Integer;
begin
  Result := TComparer<string>.default.Compare( L.FFileName, R.FFileName );
end;

{ TLogFileList }

constructor TLogFileList.Create;
begin
  inherited Create( TComparer<TLogFile>.Construct( TLogFile.IdentityCompare ), AOwnsObjects );
end;

end.
wenn man die Methoden als static markiert

Zusätzlich könnte man bei der Klasse auch noch die gewünschten Comparer als class property hinterlegen ... kommt halt darauf an
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
 

 

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 23:06 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