Back to Styles.
Styles are named using the StyleName property of the style element. (See Style Names for more detail).
You’ll notice that in Introduction To FireMonkey Styles the styles where named ‘buttonstyle’. This is the default style name used for a TButton and is derived by removing the initial ‘T’ and appending the word ‘style’. When FireMonkey searches for a style for a component it will follow this algorithm first. So, for instance, the default style name for a TEdit is ‘editstyle’, ‘comboboxstyle’ for a TComboBox and so on.
If you subclass a control to create your own custom control, e.g. deriving TChildEdit from TEdit, then FireMonkey will first apply the above formula and search for ‘childeditstyle’. If none exists it will look at the parent class, TEdit, and seach for ‘editstyle’.
If you create another control, TGrandChildEdit, from TChildEdit it will look for ‘grandchildeditstyle’, then ‘childeditstyle’, but it will not look any further up the class hierarchy and thus not find the ‘editstyle’. In other words, it will look for styles for the current class and the parent class but won’t go any further up the class hierarchy.
If you ever create a a component and nothing appears when you use it bear this in mind. If this happens you can either copy the existing style (‘editstyle’) and name it appropriately for you control (‘grandchildeditstyle’) or explicitly set the StyleLookup property of your control.
Most components also have a StyleLookup property. You can specify the name of a style element here to override the default naming convention.
Style Lookup Sequence
FireMonkey searches for a style to apply to a control in a specific sequence:
- If the StyleLookup property of the control is specified it looks first in the style book specified in the StyleBook property of the form.
- It then looks for the element named in StyleLookup in the app-wide style specified in either ActiveStyle or ActiveStyleHiRes (as appropriate) of TStyleManager.
- If no StyleLookup is specified it will use the naming scheme used above to search the style book.
- If that fails it will use the default naming scheme to search the ActiveStyle or ActiveHiRes style of TStyleManager.