How to get enumeration type into stringlist?
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(Ty开发者_如何学GopeInfo('TAlign'), 1));
Thanx
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;
精彩评论