Author: Tomas Rutkauskas
I need to get a list of strings (like a StringList) with the possible values for a
TBrushStyle property (bsSolid, bsClear, bsHorizontal, for example). I want to build
a ComboBox with this options. How can I set the property Items of my ComboBox
directly with all the values from the enumerated type TBrushStyle? My ComboBox will
be alike the Property Editor for this type.
Answer:
You can use runtime type information (RTTI) to do that. Below is an example:
1 uses2 {...}, TypInfo
3 4 procedure BrushStylesAsStrings(AList: TStrings);
5 var6 a: integer;
7 pInfo: PTypeInfo;
8 pEnum: PTypeData;
9 begin10 AList.Clear;
11 pInfo := PTypeInfo(TypeInfo(TBrushStyle));
12 pEnum := GetTypeData(pInfo);
13 with pEnum^ do14 begin15 for a := MinValue to MaxValue do16 AList.Add(GetEnumName(pInfo, a));
17 end;
18 end;