Einzelnen Beitrag anzeigen

Benutzerbild von Gausi
Gausi

Registriert seit: 17. Jul 2005
905 Beiträge
 
Delphi 12 Athens
 
#2

AW: Operator in If Then Anweisung als Variable möglich ?

  Alt 26. Mai 2020, 20:36
So direkt geht das nicht. Du könntest aber eine Compare-Funktion schreiben, die nicht nur a und b als Parameter hat, sondern auch den Vergleichsoperator. Letzteren dargestellt als Char, Integer oder (vermutlich am sinnvollsten) Aufzählungstyp.

Delphi-Quellcode:
function MyCompare(a,b: Integer; operator: TMyOperatorEnum): boolean;
begin
  case operator of
    op_lesser: result := a < b;
    op_bigger: result := a > b;
    op_lesser_eq: result := a <= b;
    // ...
  end;
end;
Being smart will count for nothing if you don't make the world better. You have to use your smarts to count for something, to serve life, not death.
  Mit Zitat antworten Zitat