There is nothing wrong with your television set. Do not attempt to adjust the picture.
The TStateMachine component is used to create Finite State Machines visually in the Delphi IDE.
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.
The TStateMachine library contains the following components:
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:
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:
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:
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:
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.
Specialized TStateNode. Used for the entry state but optional.
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”.
D1 | D2 | D3 | D4 | D5 | D6 | D7 | D2005 | D2006 | D2007 |
This work is licensed under a
Creative Commons Attribution-Share Alike 3.0 Unported License.
Download: | TStateMachine v2.2 for Delphi |
---|---|
Version: | 2.2 |
Updated: | 4 April, 2006 |
Size: | 12.55 KB |
Notes: | |
Downloads: | 4,469 |
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:
|
Downloads: | 6,918 |
Have you ever thought about creating a collection of statemachines within a single TComponent descendant?
It could be used in a datamodule if reworked this way.
Right click on component to bring up component editor. Next each state machine could be represented on a different tab page. All setting could be saved with component. You could design some very elaborate functionality but with clear visual representation.
Just wondering…
Not really, but I have considered something similar; When designing large complex state machines, I have often wished that it was possible to have parts of the state diagram represented by separate TStateMachine components. Or to put it another way; I would like to be to call one TStateMachine from another.
One of the problems with making TStateMachine descend from TComponent, instead of TControl, is that I would have to implement my own state diagram designer, instead of (mis)using the form designer as I do now. Not an impossible task at all. Just more work than I'm willing to invest right now.
Where could i find a valid download link for TStateMachine?
Your site link isn’t good and, on the web, I only found old version (v1.1)…
I assume you are using Internet Explorer.
FireFox downloads just fine, but I have reproduced the problem with IE7 and will investigate. I expect to have a solution by tomorrow.
I believe the problem has been resolved.
Let me know if you have any further problems.
I get an exception in
Do you have a working example of using Statmach?
Old Minimal StateMachine Demo (1998) does not work anymore.
I use Turbo Delphi Pro 2006
Thanks
I'll investigate the assertion error and report back ASAP.
The only working state machines I have are rather large, but I think I have one that may be suitable as an example; It’s an auto updater that uses BITS. I had planned to write a separate article about it, but haven't found time yet.
Anyway, I'll post it soon, but I need to clean it up a bit first.
Dear Anders,
how soon is soon? Would be enough to have a working Minimal Statemachine Demo to get me going.
Thanks
Hej Anders,
interessant State Machine, som jeg godt kan se vil kunne indgå
i noget vi laver.
Jeg har kørt v. 1.01 og v. 2.02.
I begge versioner øjner jeg nogle forbedringsmuligheder.
Vil du kontakte mig via mail, så vi kan snakke nærmere?
mvh Christian
I too would be very interested in a minimal demo
This state machine is marvelous….. but one thing, after I stopped the execution of the state machine, if I execute() again it will give an error "No initial state specified". How to overcome this error?
Thanks!
Is there any demo application for the TStateMachine.
Hey Anders, still no time for a minimal demo application? I cant make it work with D2006. Please adapt your old demos from 1998/99 to work with version 2.2. or make a simple new one to get me going. Your idea is good and there is no other for the delphi language. So please help to let me use your components.
Yours
Jürgen Kehrel
Sorry to have kept you all waiting for so long.
I've had a small demo for some time but since it surfaced a new bug I decided to fix the bug first. That unfortunately turned out to be a bigger task than I anticipated. The large demo I mentioned earlier turned out to have too many dependencies on other libraries to be useful as a demo.
The good news is that I now seem to have resolved the bug and will publish a new release (including the demo) ASAP. I will try to find time to upload a temporary kit tomorrow.
Hi Anders;
Great Tool buddy, we need a simple demo please.
Thank you.
I have uploaded a beta release of version 2.3. It has been tested with Delphi 5, 7, 2007 and 2009 using the bundled demo application.
If no serious bugs surface I aim to release this as the final version 2.3 within a fortnight.
Pizzatron2000 compiles with D2006 as well. Thanks.
Jürgen
"
soSingleStep
" seems does not work?I must admit I haven't tested
soSingleStep
lately, so you could very well be right.I'll give it a go, but I'm tempted to just remove the feature unless it's really easy to fix.
Pizzatron2000 demo compiles with Delphi 6 as well.
it is very innovative component. just wondering if this component could use to design thread flow?
thanks and salute
I'm afraid I don't know what you mean by thread flow.
sorry for my unclear statement.thread flow i mean a flowchart in a thread or a code in a thread.i ask this because tstatemachine lay on tfrom which not thread safe.how to implement code design with state machine to execute in a thread.execute? thanks
hallo…sorry for my unclear statement.thread flow i mean a flowchart in a thread or a code in a thread.i ask this because tstatemachine lay on tfrom which not thread safe.how to implement code design with state machine to execute in a thread.execute? thanks
Hello:
Someone has an example to share or some kind of tutorial
The v2.3 beta includes a demo application.
I'd like to use this component as a high level flow diagram in my application. I want a state to start an activity in my application and wait for the activity to complete ( it may be downloading code to a device through the comport) , then move to the next state ( the download passed or failed).
It seems that the deisgn is such that it wants to run to completion, but I want it to suspend while my stuff is going on. When my activity competes I like to signal the state machine to continue.
you can do with loop with tstateboolean. so its not necessary do in separate tstatemachine
How to install this component?
Thanks
Alexandre
Just add it to a design time package.
I installed with "Component" -> "Install Component" -> "Install new package". I choose the unit and named the package.
I have tested this day. Is it possible to insert a extra line in the component do show more description about the state?
Thanks
Alexandre
I'm not sure what you mean. Insert an extra line where?
Sorry!. The problem is that the name of itens is insuficient to describe them. With a extra line in the component, I could put the descrition.
Thanks again.
Alexandre
Have you tried the
Hint
property?Good idea!
What the meaning of: Synchronize?
I assume you mean the
TStateControl.Synchronize
property.The
Synchronize
property, if True, specifies that events are executed in the context of the main thread. If it is False, the events are executed in the context of the scheduler thread. SeeTThread.Synchronize
or one of the many articles about threads and GUI.The
soSynchronize
value ofTStateMachine.Options
can be used to specify that all events must be synchronized.soSynchronize
is set by default.Unless you understand the implications you should just leave
soSynchronize
set.can it use to code in a tthread class?