Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit System.Helpers.EnumTypes;
- interface
- Uses System.Classes,System.Generics.Collections,System.Generics.Defaults,TypInfo,RTTI,Variants,System.SysUtils;
- Type
- TRAnge = 0..255;
- TEnum<T:record> = class
- public
- class function &to<X>(const eEnum:T; Arg: TArray<X>):X; overload;
- end;
- implementation
- class function TEnum<T>.&to<X>(const eEnum: T; Arg: TArray<X>): X;
- var
- P:PInteger;
- Num:integer;
- begin
- try
- P:=@eEnum;
- Num:=integer(TRAnge((P^)));
- Result := Arg[Num];
- except
- raise EConvertError.Create(
- 'O Parâmetro passado não corresponde a '+sLineBreak+
- 'um inteiro Ou a um Tipo Enumerado');
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement