The Delphi Geek: Using Generics to Manipulate Enumerated Types
Posted by jpluimers on 2020/11/18
Not that this is bad code, but there are no unit tests for them, and I have seen places in the wild that blindly use it without documenting where it came from and what tested alternatives might be: [WayBack] The Delphi Geek: Using Generics to Manipulate Enumerated Types
The unit itself is down (though there is still a copy on the WayBack machine).
The post itself mentions it is Spring4D-inspired, and since Spring4D already has quite an extensive [WayBack] TEnum<T>
implementation covered by unit tests, so that is a logical place to do for.
I might actually document the migration table if I find time for it.
Here is a start so I will only have to insert the blanks
Function Replacement class function Clip(const value: Integer): T; class function Clip(const value: T): T; class function Ensure(const value: Integer; const min, max: T): T; class function Ensure(const value, min, max: T): T; class function FromInt(const value: Integer): T; class function Enum: RangeEnum; static; class function GetValueOrDefault(const value: Integer): T; class function IsValid(const value: Integer): Boolean; class function IsValid(const value: T): Boolean; class function Max: T; static; class function Min: T; static; class function ToInt(const value: T): Integer; class function ToString(const value: T): string;
–jeroen
Leave a comment