Although you give Boolean as an example in your question, I'm going to suggest that you are really interested in the complete commonality of the types listed. Otherwise, you simply call StrToBool .
TValue not intended to perform the conversion you are trying to perform. Ultimately, at the lower level, the GetEnumValue and GetEnumName in the System.TypInfo module are the functions that perform these conversions.
In modern versions of Delphi, you can use TRttiEnumerationType to convert from text to an enumerated type value:
b := TRttiEnumerationType.GetValue<Boolean>(s);
You can move in the other direction as follows:
s := TRttiEnumerationType.GetName<Boolean>(b);
These methods are implemented with calls to GetEnumValue and GetEnumName respectively.
Older versions of Delphi hide TRttiEnumerationType.GetValue and TRttiEnumerationType.GetName as private methods. If you are using such a version of Delphi, you should use GetEnumName .
source share