You can get the part there using the write helper, which is available for value types from XE3 onwards. For example:
{$APPTYPE CONSOLE} uses System.SysUtils, System.TypInfo; type TMyEnum = (enumValue1, enumValue2); TMyEnumHelper = record helper for TMyEnum public function ToString: string; end; function TMyEnumHelper.ToString: string; begin Result := GetEnumName(TypeInfo(TMyEnum), ord(Self)); end; begin Writeln(enumValue1.ToString); Writeln(enumValue2.ToString); end.
This program displays the following:
enumValue1
enumValue2
Of course you can do it like this:
{$APPTYPE CONSOLE} uses System.SysUtils, System.TypInfo; type TMyEnum = (enumValue1, enumValue2); TMyEnumHelper = record helper for TMyEnum private const EnumNames: array [TMyEnum] of string = ('Friendly name 1', 'Friendly name 2'); public function ToString: string; end; function TMyEnumHelper.ToString: string; begin Result := EnumNames[Self]; end; begin Writeln(enumValue1.ToString); Writeln(enumValue2.ToString); end.
The output is here:
Friendly name 1
Friendly name 2
This, apparently, will allow you to solve the fact that the listed Delphi types do not support the text naming available in Java.
Another method, the HTTPHeaderKey constructor, HTTPHeaderKey not be supported by the listed type. The reason is that this requires a state, and the only state for the Delphi enumerated type is the value of the enumerated type itself. You cannot transplant an additional instance variable, as is done in Java code.
All things considered, I donβt think that trying on a literal translation with an enumerated type will work. I suggest you translate using either a record or a class and create equivalent functionality using the available Delphi language constructors.
David heffernan
source share