My function EnumToStringList on its own can be compiled, but I can’t call it with any enum type, in my app.
Error : **[dcc64 Error] Unit_test.pas(119): E2029 '(' expected but ')' found**
What is wrong with my approach ?
function EnumToStringList(const TypeInfo: pTypeInfo): TStringlist;
var i : Integer;
begin
Result := TStringList.Create;
for i := GetTypeData(TypeInfo)^.MinValue to GetTypeData(TypeInfo)^.MaxValue do
begin
result.add (GetEnumName(TypeInfo, i));
end;
end;
function EnumToString(const TypeInfo: pTypeInfo; Ix: Integer): string;
begin
result := GetEnumName(TypeInfo, Ix);
end;
/// test code :
TProjectTypes = (low,hot,skip,pause,others);
MyProjectStrings := EnumToStringList (TProjectTypes);
>Solution :
You cannot directly pass enumeration type to your function. You need to get its type info first by calling TypeInfo on it.
var
MyProjectStrings := EnumToStringList(TypeInfo(TProjectTypes));