[fpc-pascal] generic way of writing Sets or Enum values to a String

leledumbo leledumbo_cool at yahoo.co.id
Tue Sep 6 19:07:48 CEST 2016


> Is there a way to have a single implementation of Enum-to-String or 
> Set-to-String (and the reverse), but pass in the type, instead of having 
> a separate implementation of each Enum or Set types. 
> 
> Could RTTI help? Could Generics help? Is there some other language 
> construct I might have missed? 

Take mine:

generic function EnumValueNameOf<T>(v: T): String;
begin
  Result := GetEnumName(TypeInfo(T), LongInt(v));
end;

guess you already know how to use it, don't you?



--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/generic-way-of-writing-Sets-or-Enum-values-to-a-String-tp5726280p5726281.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.



More information about the fpc-pascal mailing list