Creating the command class

Command objects are what you use to encapsulate a change to selected data in a model. The Basic Document framework provides a template class for commands, TCommandOn<ATarget>, that defines the basic protocol for commands.

TCommandOn<ATarget> provides the public functions that are called when a command is executed (for example, the Do member function). When you create a command class derived from TCommandOn<ATarget>, however, you implement the behavior of the command by overriding TCommandOn<ATarget> protected functions, including:

These command functions assume that the caller has already locked the model.

HandleDoBegin is the only pure virtual function--you must implement this function in each command class. Whether you implement other functions depends on the command. For example, HandleDoIncrement and HandleDoEnd are used to implement incremental commands and HandleUndo is used to undo the work of the command.

NOTE For more detailed information on commands, read the section "Functors and commands: accessing and changing document data" in the chapter "Basic Document framework concepts" in Desktop Framework Concepts.

The command for the Tiles program--TChangeColorCommand--derives from TCommandOn<TTilesSelection>. TChangeColorCommand takes an instance of TRGBColor in its constructor, and changes the tiles in the target selection to that color.

TChangeColorCommand isn't an incremental command, so all the work of the command is done in the HandleDoBegin function. Note that this function doesn't access the model directly, but calls TTilesSelection functions to modify the data model.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker