country := Map.GetCountryCode<CountryCode2>('DE'); //erwartetes Ergebnis: Enumerator CountryCode2_DE aus
Unit PDF_Xpansion_Wrapper_16_TLB;
class function Map.GetCountryCode<T>(aLKZ: String) : T;
var
lLKZ : string;
begin
......
lLKZ := 'CountryCode2_' + copy(lLKZ,1,2); //nur die ersten beiden Stellen übertragen = USA -> US
Result := TEnumUtils.GetEnumFromString<T>(lLKZ);
end;
class function TEnumUtils.GetEnumFromString<T>(aEnumString: String) : T;
var
lValue : T;
begin
lValue := TRttiEnumerationType.GetValue<T>(aEnumString); --> Fehlermeldung: Ungültige Typumwandlung (TOLEEnum = tkInteger <> tkEnumeration)
Result := T(lValue);
end;
unit System.Rtti;
class function TRttiEnumerationType.GetValue<T{: enum}>(const AName: string): T;
var
v: Integer;
begin
case PTypeInfo(TypeInfo(T))^.Kind of
tkEnumeration:
case System.TypInfo.GetTypeData(TypeInfo(T))^.OrdType of
otUByte, otSByte: PByte(@Result)^ := GetEnumValue(TypeInfo(T), AName);
otUWord, otSWord: PWord(@Result)^ := GetEnumValue(TypeInfo(T), AName);
otULong, otSLong: PInteger(@Result)^ := GetEnumValue(TypeInfo(T), AName);
end;
else
raise EInvalidCast.CreateRes(@SInvalidCast);
end;
end;
unit PDF_Xpansion_Wrapper_16_TLB;
// Konstanten für enum CountryCode2
type
CountryCode2 = TOleEnum;
const
CountryCode2_unk = $00000000;
CountryCode2_AL = $0000414C;
CountryCode2_AD = $00004144;
CountryCode2_AT = $00004154;
CountryCode2_BA = $00004241;
CountryCode2_BG = $00004247;
CountryCode2_CA = $00004341;
CountryCode2_CN = $0000434E;
CountryCode2_HR = $00004852;
CountryCode2_CZ = $0000435A;
CountryCode2_CY = $00004359;
CountryCode2_DK = $0000444B;
CountryCode2_EE = $00004545;
CountryCode2_FI = $00004649;
CountryCode2_FR = $00004652;
CountryCode2_DE = $00004445;
....
unit WinAPI.ActiveX
TOleEnum = type LongWord;