How to Use Styles > Working with Style Properties > Named styles versus anonymous styles |
When setting style properties at design time, it is important to understand the distinction between named styles and the anonymous styles exposed by grid properties.
Named styles provide templates that govern the appearance of the grid, its splits, and its columns. At design time, you can create, modify, and delete named styles using the Style Factory property page. At run time, the Styles collection is used to represent the same set of named Style objects.
When a grid is first created, several of its style properties inherit their attributes from named styles. Within the property tree on the General page, such properties are indicated by the presence of a style name in square brackets. The following figure shows four TDBGrid properties that return named style objects: EvenRowStyle, FilterBarStyle, FooterStyle, and HeadingStyle.
Anonymous styles are not members of the Styles collection, however. They are provided so that you can easily and directly customize the appearance of an individual split or column without having to define a separate named style.
When a grid is first created, all style properties of its Split and Column objects return anonymous styles. Therefore, within the property tree on the Splits page of TDBGrid (or the Columns page of TDBDropDown), there are no style properties tagged with a name enclosed in square brackets. The following figure shows three Column properties that return anonymous style objects: FooterStyle, HeadingStyle, and Style.
The following analogy should help to clarify the distinction between named and anonymous styles. Consider a Microsoft Word document that consists of several paragraphs based on the default normal style. Suppose that one of the paragraphs is a quotation that needs to be indented and displayed in italics. If the document is part of a larger work that contains several quotations, it makes sense to define a special style for that purpose and apply it to all paragraphs that contain quotations. If the document is an early draft or is not likely to be updated, defining a style for one paragraph is overkill, and it would be more convenient to apply indentation and italics to the quotation itself.
In this analogy, specifying paragraph attributes directly is akin to setting the members of a property that returns an anonymous style. For example, if you want cell data to be vertically centered within a particular grid column, you can modify the VerticalAlignment member of the column's Style property on the Splits property page.
Note that modifying an anonymous style is just like modifying a named style. You first expand the desired Style object node in a property tree, then select and edit one or more of its member properties.