operator-overloadingdelphi-xe5

Operator overloading for built-in data types and enums


Is overloading of implicit type conversion possible for enumerations in Delphi?

program TriState;

type
  TTrilean = (trNone = -1, trFalse = 0, trTrue = 1);
  TTrileanHelper = record helper for TTrilean
  public
    class operator Implicit(...)...; //E2123 PROCEDURE, FUNCTION, PROPERTY, or VAR expected
  end;

var
  v: TTrilean;

begin
  v := trNone;
  v := True; //Would like to have class operator Implicit here
end.

Solution

  • In the Delphi 10.4.2 documentation I read:

    Note: Class and record helpers do not support operator overloading.