In Step 3, you saw how to issue a command against a target selection using a command binding. When a user selected a tile, the TTilesView MouseDown function created the TTilesSelection and immediately issued a TChangeColorCommand against it. In Step 4, you saw how to encapsulate the user's selection and maintain it as the current selection, so that the user could first make a selection and then decide how to operate on the selected data.
In this step you create a control state which encapsulates the operation represented by a menu item. When the user selects a menu item, the control state's Select function causes the corresponding command to be issued against the current selection.
The Presentation framework provides a template class, TCommandControlStateOn<ATarget>, that you can use as is for a momentary control state that, when selected, initiates a command on the current selection. This Tiles menu uses this control state to issue commands--TChangeColorCommand and TCreateTileCommand--against the current TTilesSelection.
At construction, TCommandControlStateOn<TTilesSelection> requires a prototype of the command to initiate and a reference to the GUI bundle for the document component so it can access the current selection. When a user activates a control based on this control state, the Select function:
For example, this diagram shows how TCommandControlStateOn<TTilesSelection> binds a TChangeColorCommand to a TTilesSelection:
NOTE The TCreateTileCommand, described in "Implementing TCreateTileCommand" on page 90, also gets bound to a TTilesSelection using this control state.