1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
type
TEnum = (eUn, eDeux, eTrois, eQuatre);
TTest = class
strict private
FEnum: TEnum;
public
function ToString: string; override;
property Enum: TEnum read FEnum write FEnum;
end;
TTestComparer = class(TComparer<TTest>)
public
function Compare(const Left, Right: TTest): Integer; override;
end;
{ TTest }
function TTest.ToString: string;
begin
case FEnum of
eUn: Result := 'Un';
eDeux: Result := 'Deux';
eTrois: Result := 'Trois';
eQuatre: Result := 'Quatre';
end;
end;
{ TTestComparer }
function TTestComparer.Compare(const Left, Right: TTest): Integer;
var
e1, e2: Integer;
begin
e1 := Ord(Left.Enum);
e2 := Ord(Right.Enum);
if e1 = e2 then
Result := 0
else if e1 < e2 then
Result := -1
else
Result := 1;
end; |