Reputation: 2619
This single line of code:
ShowMessage(GetEnumName(TypeInfo(TAlign), 1));
returns "alTop".
How can I get all values of enumerated type into stringlist, when I want to use string variable: 'TAlign' instead of TAlign? Something like:
ShowMessage(GetEnumName(TypeInfo('TAlign'), 1));
Thanx
Upvotes: 4
Views: 4149
Reputation: 84550
To be able to use a string variable, you'd need to register the TypeInfo with the string in some sort of lookup table, and then look it up.
To get all the enumerated type names in your list, you can do something like this:
procedure LoadAllEnumValuesIntoStringList(enum: PTypeInfo; list: TStringList);
var
data: PTypeData;
i: integer;
begin
list.clear;
data := GetTypeData(GetTypeData(enum)^.BaseType^);
for i := 0 to data.MaxValue do
list.add(GetEnumName(enum, i));
end;
Upvotes: 7