Registriert seit: 18. Aug 2004
Ort: Edewecht
712 Beiträge
Delphi 5 Professional
|
Re: Übergabeparameter verfälscht bei Aufruf einer Funktion
31. Mär 2005, 23:57
Delphi-Quellcode:
type
TIntegerComparerFunc = function(X, Y: Integer): Integer of object;
TIntegerComparer = class(TObject)
private
FComparerFunc: TIntegerComparerFunc;
public
function Compare(X, Y: Integer): Integer;
property CustomCompare: TIntegerComparerFunc read FComparerFunc write FComparerFunc;
end;
Delphi-Quellcode:
function TIntegerComparer.Compare(X, Y: Integer): Integer;
begin
if Assigned(FComparerFunc) then
Result := FComparerFunc(X, Y)
else
begin
if X = Y then
Result := 0
else if X < Y then
Result := -1
else
Result := 1;
end;
end;
oder so: Wenn du lieber Prozeduren anstatt von Methoden bevorzugst.
Delphi-Quellcode:
type
TIntegerComparerFunc = function(X, Y: Integer): Integer;
TIntegerComparer = class(TObject)
private
FComparerFunc: TIntegerComparerFunc;
public
function Compare(X, Y: Integer): Integer;
property CustomCompare: TIntegerComparerFunc read FComparerFunc write FComparerFunc;
end;
Delphi-Quellcode:
function TIntegerComparer.Compare(X, Y: Integer): Integer;
begin
if Assigned(FComparerFunc) then
Result := FComparerFunc(X, Y)
else
begin
if X = Y then
Result := 0
else if X < Y then
Result := -1
else
Result := 1;
end;
end;
Ciao, Sprint.
"I don't know what I am doing, but I am sure I am having fun!"
|
|
Zitat
|