How to retrieve all available TBrushStyle values as a list of strings #222

Question
I need to get a list of strings (like a string list) with the possible values for a TBrushStyle property (bsSolid, bsClear, bsHorizontal, for example). I want to build a combo box with these options. How can I set the Items property of my combo box directly with all the values from the enumerated type TBrushStyle? My combo box will be like the property editor for this type.

You can use runtime type information (RTTI) to do that. Below is an example:

uses 
  {...}, TypInfo
 
procedure BrushStylesAsStrings(AList: TStrings);
var
  a: integer;
  pInfo: PTypeInfo;
  pEnum: PTypeData;
begin
  AList.Clear;
  pInfo := PTypeInfo(TypeInfo(TBrushStyle));
  pEnum := GetTypeData(pInfo);
  with pEnum^ do
  begin
    for a := MinValue to MaxValue do
      AList.Add(GetEnumName(pInfo, a));
  end;
end;
Original resource: The Delphi Pool
Author: Sen
Added: 2013/04/09
Last updated: 2013/04/09