Stateflow User's Guide Previous page   Next Page

Creating Stateflow Objects

You create a Stateflow object as the child of a parent object through API constructor methods. Each Stateflow object type has its own constructor method. See Constructor Methods for a list of the valid constructor methods.

Use the following process to create Stateflow objects with the Stateflow API:

  1. Access the parent object to obtain a handle to it.
  1. When you first begin populating a model or chart, this means that you must get a handle to the Stateflow Model object or a particular Chart object. See Access the Model Object and Access the Chart Object.

    See also Accessing Existing Stateflow Objects for a more general means of accessing (getting an object handle to) an existing Stateflow object.

  1. Call the appropriate constructor method for the creation of the object using the parent (containing) object as an argument.
  1. For example, the following command creates and returns a handle s to a new state object in the chart object with the handle ch:

    By default, the newly created state from the preceding command appears in the upper left-hand corner of the Stateflow chart (at x-y coordinates 0,0).

    The constructor returns a handle to an API object for the newly created Stateflow object. Use this handle to display or change the object through its properties and methods.

  1. Use the object handle returned by the constructor to make changes to the object in Stateflow.
  1. For example, you can now use the handle s to set its name (Name property) and position (Position property). You can also connect it to other states or junctions by creating a Transition object and setting its Source or Destination property to s. See Create New Objects in the Chart for examples.

Use the preceding process to create all Stateflow objects in your chart. The section Create New Objects in the Chart gives examples for creating states and transitions. Objects of other types are created just as easily. For example, the following command creates and returns a handle (d1) for a new Data object belonging to the state A (handle sA):


Previous page  Creating and Destroying API Objects Establishing an Object's Parent (Container) Next page

© 1994-2005 The MathWorks, Inc.