The TStateMachine component is used to create Finite State Machines visually in the Delphi IDE.

TStateMachine at design time - Click to view run time

TStateMachine makes it very easy to design and implement simple and medium complex state machines. Instead of using loops, case and if statements to control the flow of your application, TStateMachine allows you to concentrate on implementing the core functionality and logic of your state machine.

TStateMachine manages the transition (flow) from one state to another and can automatically check the validity of transitions. All you have to do is define what a given state does, what transitions to make (conditional branches) and how to move from one state to another (transitions).

The state machine components were originally designed for use in “Voice Response” applications, but they can just as easily be used in any other types of applications.

Besides being used as a production tool to implement actual state machines it is also used as a prototyping tool to design and test state machines.

To aid in debugging and monitoring the state machine, TStateMachine can optionally display the execution of the statemachine visually at run-time and even allows you to single step through the state machine.

TStateMachine is not a full featured state machine builder and instead of the more traditional Moore and Mealy semantics and ASM notation, it uses a much simpler flow diagram metaphor.

Components

The TStateMachine library contains the following components:

TStateMachine componentTStateMachine

This component manages the flow of execution through the state machine.
You define your state machine by dropping state components on a TStateMachine and connecting the states with transitions. It is not possible to link one TStateMachine to another although this may be done manually in code.
In ASM notation a TStateMachine would be called a “Block”.

TStateMachine defines the following events:

  • OnChangeState
    Occurs whenever the state machine changes to a new state.
  • OnException
    Occurs if an exception is thrown inside a state event handler.

TStateNode component TStateNode

Defines a single state in the state machine.
Most of the work in a state machine will typically be done inside TStateNode components. Transition from a TStateNode to another state can either be done by explicitely jumping to another state (or TStateTransition node) or by executing a default transition specified by the DefaultTransition property.

In ASM notation this would be called a “State Box”.

TStateNode defines the following events:

  • OnEnterState
    Occurs when the state machine enters the state. This is the typical place to define what a given state actually does.
  • OnExitState
    Occurs when the state machine leaves the state.

TStateTransition component TStateTransition

Defines a transition from one state to another.
A TStateTransition defines a transition from one state to another state. It is often used to define alternate transitions (transitions other that the defaults) since default transitions are defined by the individual states.
In other notations this is often refered to as a path.

TStateTransition defines the following events:

  • OnTransition
    Occurs when the transition is executed.

TStateBoolean component TStateBoolean

Same as TStateNode, but specialized for true/false branches.
Transition from a TStateBoolean is done by setting a boolean return value in the OnEnterState event handler. If a True value is set the transition specified by the TrueState property is executed, otherwise the transition specified by the FalseState property is executed.
In ASM notation this would be called a “Condition Box”.

TStateTransition defines the following events:

  • OnEnterState
    Occurs when the state machine enters the state.
  • OnExitStateOccurs when the state machine leaves the state.

TStateLink component TStateLink

Used to connect one part of a diagram with another.
Commonly used to connect distant nodes. Used in pairs to specify a source and a destination. No connector line is drawn between the source and destination nodes.

TStateStart component TStateStart

Specialized TStateNode. Used for the entry state but optional.

  • OnEnterStateOccurs when the state machine enters the state.
  • OnExitState
    Occurs when the state machine leaves the state.

TStateStop component TStateStop

Specialized TStateNode. Used for the exit state but optional.
Does not have a DefaultTransition property as execution of the state machine will typically stop at this node.
In ASM notation this could be called an “Output Box” or a “terminal state”.

Requirements

D1 D2 D3 D4 D5 D6 D7 D2005 D2006 D2007
Fail Unknown Unknown Unknown Pass Unknown Pass Unknown Unknown Unknown

License

Creative Commons License
This work is licensed under a
Creative Commons Attribution-Share Alike 3.0 Unported License.

Download

download
Download: TStateMachine v2.2 for Delphi
Version: 2.2
Updated: 4 April, 2006
Size: 12.55 KB
Notes:
Downloads: 3,656

download
Download: TStateMachine v2.3 for Delphi
Version: 2.3
Updated: 15 February, 2009
Size: 39 KB
Notes: Version 2.3 beta release. Includes a demo application.
Changes since v2.2:
  • Fixed assertion error when altering state before state machine is started.
  • Fixed restart of stopped state machine.
  • Fixed thread syncronization dead lock.
  • Added automatic repaint of states on transition.
Downloads: 5,346

FAQ - Frequently Asked Questions

There are no questions yet.

Request new FAQ

If you couldn't find the answer to your question, then just ask us using the form below. Please keep the question short and to the point.

Change log

  • Version 2.2 (2006-04-04)
    • Complete rewrite of threaded scheduler.
    • The message based scheduler has now been deprecated.
  • Version 2.1 (1999-08-06)
    • Added OnSingleStep event.
    • Verified Delphi 5 compatibility.
    • TStateControl.Click functionality has been deprecated.
    • Improved start/stop operation.
    • Improved thread shutdown logic.
  • Version 2.0 (1999-01-12)
    • Implemented threaded scheduler and soThreaded option.
    • Added OnStart and OnStop events.
    • Removed obsolete methods.
  • Version 1.1.1 (1998-05-18)
    • Added missing design time glyphs.
  • Version 1.1 (1998-05-09)
    • Fixed design time TStateConnector editor with help from Filip Larsen.
  • Version 1.0 (1998-03-28)
    • Implemented TStateConnector persistence.
    • Many small design time bugs fixed.
    • Implemented soSingleStep option.
  • Version 0.1 (1998-02-13)
    • Released for public beta.