AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Object-Pascal / Delphi-Language Delphi Übergabeparameter verfälscht bei Aufruf einer Funktion
Thema durchsuchen
Ansicht
Themen-Optionen

Übergabeparameter verfälscht bei Aufruf einer Funktion

Ein Thema von Arakis · begonnen am 31. Mär 2005 · letzter Beitrag vom 1. Apr 2005
Antwort Antwort
Muetze1
(Gast)

n/a Beiträge
 
#1

Re: Übergabeparameter verfälscht bei Aufruf einer Funktion

  Alt 31. Mär 2005, 22:39
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
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:26 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz