Prev Next

Recording and Mapping State Changes

This topic discusses how to set constraints against each State in the StateMachine under a Class, to define the change in state to be recorded.


This example of a State 'Properties' dialog is for the State called Parliament; the 'Constraints' tab is open to show how the State is linked to the Class CXTrain.

A State can be defined by a single constraint or by many; in the example, the Parliament State has two constraints:

The values of constraints can only be compared for elemental, enum and string types

The CXTrain Class has a member called Location of type int, and a member called Departing.Name of type CString; what this constraint means is that this State is evaluated to True when:

  • an instance of the CXTrain Class exists and
  • its member variable Location has the value 0 and
  • the member variable Departing.Name has the value Parliament

Operators in Constraints

There are two types of operator you can use on constraints to define a State:

  • Logical operators AND and OR can be used to combine constraints
  • Equivalence operators {= and !=} can be used to define the conditions of a constraint

All the constraints for a State are subject to an AND operation unless otherwise specified; you can use the OR operation on them instead, so you could rewrite the constraints in the example as:

     Location=0 OR

     Location=1 AND


Here are some examples of using the equivalence operators:

     Departing.Name!=Central AND



  • Quotes around strings are optional; the comparison for strings is always case-sensitive in determining the truth of a constraint

Learn more