* Added Delegatedcomparer for Delphi compatibility

This commit is contained in:
Michaël Van Canneyt 2024-02-16 16:13:19 +01:00
parent 89f0e052df
commit 59d0af7f65

View File

@ -55,6 +55,7 @@ type
TOnComparison<T> = function(const Left, Right: T): Integer of object;
TComparisonFunc<T> = function(const Left, Right: T): Integer;
TComparison<T> = reference to function(const Left, Right: T): Integer;
TComparer<T> = class(TInterfacedObject, IComparer<T>)
public
@ -80,6 +81,14 @@ type
function Compare(const ALeft, ARight: T): Integer; override;
constructor Create(AComparison: TComparisonFunc<T>);
end;
TDelegatedComparer<T> = class(TComparer<T>)
private
FCompareFunc: TComparison<T>;
public
constructor Create(const aCompare: TComparison<T>);
function Compare(const aLeft, aRight: T): Integer; override;
end;
IEqualityComparer<T> = interface
function Equals(const ALeft, ARight: T): Boolean;
@ -1121,6 +1130,18 @@ begin
FComparison := AComparison;
end;
constructor TDelegatedComparer<T>.Create(const aCompare: TComparison<T>);
begin
FCompareFunc:=aCompare;
end;
function TDelegatedComparer<T>.Compare(const aLeft, aRight: T): Integer;
begin
Result:=FCompareFunc(aLeft, aRight);
end;
{ TInterface }
function TInterface.QueryInterface(constref IID: TGUID; out Obj): HResult;