» Help

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

Question 1
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 this options. How can I set the property Items 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:

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

« Return to contents »