Class TState

Unit

Declaration

type TState = class(TObject)

Description

Base class for states.

TState implements an abstract class to define a state. It introduces methods to define the behaviour of this state.

You can use the states or through a TStateMachine. Note that the object that uses the state may be not the Owner of the state. The owner is the object that contains the state. The object that uses the state is passed as a parameter to the Update method.

An instance of TState is never created directly, instead a descendant should be created. This is because TState is an abstract class which does not implement all methods.

See also
TStateMachine
A State Machine implementation.

Hierarchy

  • TObject
  • TState

Overview

Methods

Protected procedure SetName (const aValue: AnsiString); virtual;
Public constructor Create; virtual;
Public procedure Enter (aEntity: TObject); virtual;
Public procedure Update (aEntity: TObject); virtual; abstract;
Public procedure Leave (aEntity: TObject); virtual;

Properties

Public property Name: AnsiString read fName write SetName;

Description

Methods

Protected procedure SetName (const aValue: AnsiString); virtual;

Sets name.

Public constructor Create; virtual;

Constructor.

Public procedure Enter (aEntity: TObject); virtual;

Prepare the state to be used.

This is called before the first use of the state to initialize it and the entity.

Parameters
aEntity
Object entity asociated with the state.
See also
TState.Leave
Clean state after using it.
Public procedure Update (aEntity: TObject); virtual; abstract;

Execute state.

Parameters
aEntity
Object entity asociated with the state.
See also
TState.Enter
Prepare the state to be used.
TState.Leave
Clean state after using it.
Public procedure Leave (aEntity: TObject); virtual;

Clean state after using it.

This is called after the last use of the state, because it changed, to clean and release resources when needed.

Remember that this method is called only when changing states and not when destroyed, so you should also add cleaning code in the destructor.

Parameters
aEntity
Object entity asociated with the state.
See also
TState.Enter
Prepare the state to be used.

Properties

Public property Name: AnsiString read fName write SetName;

State name.


Generated by PasDoc 0.15.0. Generated on 2025-07-31 11:41:01.