Advertisement
TLama

Untitled

Jul 15th, 2015
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.40 KB | None | 0 0
  1. uses
  2.   TypInfo;
  3.  
  4. function StrToCustomType(const Value: string): TCustomType;
  5. var
  6.   OrdValue: Integer;
  7. begin
  8.   OrdValue := GetEnumValue(TypeInfo(TCustomType), Value);
  9.   // if the GetEnumValue returns value different from -1, cast this value to the returned type, raise exception otherwise
  10.   if OrdValue <> -1 then
  11.     Result := TCustomType(OrdValue)
  12.   else
  13.     raise EMyException.Create(...);
  14. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement