Einzelnen Beitrag anzeigen

TurboMagic

Registriert seit: 28. Feb 2016
Ort: Nordost Baden-Württemberg
2.873 Beiträge
 
Delphi 12 Athens
 
#1

TArray welches TPair<> enthält sortieren

  Alt 26. Sep 2022, 15:21
Hallo,

warum mag mich der COmpiler hier nicht bzw. was muss ich ändern?

Delphi-Quellcode:
type
  TFailureEntry = TPair<System.Word, TMyFailureRecord>;

procedure TMyClass.GetFailureAbbreviations;
var
  FailureArray: TArray<TFailureEntry>;
  Comparison: TComparison<TFailureEntry>;
begin
  // derrive the array contents from a dictionary
  FailureArray := FFailureDictionary.ToArray;

  Comparison :=
    function(const Left, Right: TFailureEntry): Integer
    begin
      Result := Left.Key-Right.Key;
    end;

  FailureArray.Sort(TComparer<TFailureEntry>.Construct(Comparison));
end;
Er wirft einen E2018: Record, Objekt oder Kalssentyp erforderlich Fehler direkt
am Sort Aufruf. Der Construct Aufruf als solches scheint noch zu funktionieren,
ziehe ich TComparer<TFailureEntry>.Construct(Comparison); raus compiliert das noch,
bleibt aber wieder am Sort "hängen".

Grüße
TurboMagic
  Mit Zitat antworten Zitat