«« Site Rescued »»

While the site is still going to move from its current host, a new site will now take its place. More Info.

The new site may have less content, but the core will now remain. And it will now play nicely with phones! Keep an eye on the DelphiDabbler Blog for news.

» 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 »