mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-21 08:49:26 +02:00
* Added Delegatedcomparer for Delphi compatibility
This commit is contained in:
parent
89f0e052df
commit
59d0af7f65
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user