Moin!
1. Du hast als Vergleichsprocedure eine Methode:
Delphi-Quellcode:
{------------------------------------------------------------------------------}
{ TIntegerComparer
{------------------------------------------------------------------------------}
TIntegerComparerFunc = function(x: Integer; y: Integer): Integer Of Object;
TIntegerComparer = class
private
_ComparerFunc: TIntegerComparerFunc;
function GetComparerFunc: TIntegerComparerFunc;
procedure SetComparerFunc(func: TIntegerComparerFunc);
public
function Compare(x: Integer; y: Integer): Integer;
property ComparerFunc: TIntegerComparerFunc read GetComparerFunc write SetComparerFunc;
function DefaultComparerFunc(x: Integer; y: Integer): Integer;
Constructor Create;
Destructor Destroy; override;
end;
...
{------------------------------------------------------------------------------}
{ TIntegerComparer
{------------------------------------------------------------------------------}
Constructor TIntegerComparer.Create;
Begin
_ComparerFunc := DefaultComparerFunc;
End;
{------------------------------------------------------------------------------}
Destructor TIntegerComparer.Destroy;
Begin
Inherited;
End;
{------------------------------------------------------------------------------}
function TIntegerComparer.GetComparerFunc: TIntegerComparerFunc;
Begin
result := _ComparerFunc;
End;
{------------------------------------------------------------------------------}
procedure TIntegerComparer.SetComparerFunc(func: TIntegerComparerFunc);
Begin
_ComparerFunc := func;
End;
{------------------------------------------------------------------------------}
function TIntegerComparer.Compare(x: Integer; y: Integer): Integer;
begin
if x = y then
result := 0
else if (x < y) then
result := -1
else
result := 1;
//exit;
if Not Assigned(_ComparerFunc) then
RaiseException('TIntegerComparer.Compare: Keine Vergleichsfunktion festgelegt');
result := _ComparerFunc(x, y);
end;
{------------------------------------------------------------------------------}
function TIntegerComparer.DefaultComparerFunc(x: Integer; y: Integer): Integer;
begin
if x = y then
result := 0
else if (x < y) then
result := -1
else
result := 1;
end;
Oder
2. eine normale Procedure/Funktion
Delphi-Quellcode:
{------------------------------------------------------------------------------}
{ TIntegerComparer
{------------------------------------------------------------------------------}
TIntegerComparerFunc = function(x: Integer; y: Integer): Integer;
TIntegerComparer = class
private
_ComparerFunc: TIntegerComparerFunc;
function GetComparerFunc: TIntegerComparerFunc;
procedure SetComparerFunc(func: TIntegerComparerFunc);
public
function Compare(x: Integer; y: Integer): Integer;
property ComparerFunc: TIntegerComparerFunc read GetComparerFunc write SetComparerFunc;
Constructor Create;
Destructor Destroy; override;
end;
...
{------------------------------------------------------------------------------}
function DefaultComparerFunc(x: Integer; y: Integer): Integer;
begin
if x = y then
result := 0
else if (x < y) then
result := -1
else
result := 1;
end;
{------------------------------------------------------------------------------}
{ TIntegerComparer
{------------------------------------------------------------------------------}
Constructor TIntegerComparer.Create;
Begin
_ComparerFunc := DefaultComparerFunc;
End;
{------------------------------------------------------------------------------}
Destructor TIntegerComparer.Destroy;
Begin
Inherited;
End;
{------------------------------------------------------------------------------}
function TIntegerComparer.GetComparerFunc: TIntegerComparerFunc;
Begin
result := _ComparerFunc;
End;
{------------------------------------------------------------------------------}
procedure TIntegerComparer.SetComparerFunc(func: TIntegerComparerFunc);
Begin
_ComparerFunc := func;
End;
{------------------------------------------------------------------------------}
function TIntegerComparer.Compare(x: Integer; y: Integer): Integer;
begin
if x = y then
result := 0
else if (x < y) then
result := -1
else
result := 1;
//exit;
if Not Assigned(_ComparerFunc) then
RaiseException('TIntegerComparer.Compare: Keine Vergleichsfunktion festgelegt');
result := _ComparerFunc(x, y);
end;
MfG
Muetze1