filhotecmail

Enumetare

Sep 25th, 2020 (edited)
1,132
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unit System.Helpers.EnumTypes;
  2.  
  3. interface
  4.   Uses System.Classes,System.Generics.Collections,System.Generics.Defaults,TypInfo,RTTI,Variants,System.SysUtils;
  5.  
  6.  Type
  7.   TRAnge = 0..255;
  8.   TEnum<T:record> = class
  9.    public
  10.      class function &to<X>(const eEnum:T; Arg: TArray<X>):X; overload;
  11.   end;
  12.  
  13. implementation
  14.  
  15.  class function TEnum<T>.&to<X>(const eEnum: T; Arg: TArray<X>): X;
  16. var
  17.    P:PInteger;
  18.    Num:integer;
  19.  begin
  20.    try
  21.      P:=@eEnum;
  22.      Num:=integer(TRAnge((P^)));
  23.      Result := Arg[Num];
  24.    except
  25.     raise EConvertError.Create(
  26.      'O Parâmetro passado não corresponde a '+sLineBreak+
  27.      'um inteiro Ou a um Tipo Enumerado');
  28.    end;
  29.  end;
  30. end.
RAW Paste Data