TStateMachine<TState, TTrigger>.TStateConfiguration.OnEntry is never fired

304 views Asked by At

I'm using Sir Rufo's TStateless framework in Delphi 10.1 Berlin Update 2.

I'm trying to adapt this kind of workflow:

image

Here is how I have set my classes:

Some of my states does have an "OnEntry" event or an "OnExit" event :

type  
  TWarehouseCheckInState = (New, OrderChecked, ProductChecked, CartonAdded,
    Validated, Canceled);
  TWarehouseCheckInTrigger = (SetOrder, SetProduct, AddCarton, Validate, Cancel);
  TWarehouseCheckInStateMachine = TStateMachine<TWarehouseCheckInState,
    TWarehouseCheckInTrigger>;

FState.Configure(TWarehouseCheckInState.New).OnEntry(
  procedure
  begin
    FOrder := '';
    FProduct := '';
    FScannedBarCode := '';
  end
).Permitif(TWarehouseCheckInTrigger.SetOrder,
  TWarehouseCheckInState.OrderChecked,IsOrderValid);

FState.Configure(TWarehouseCheckInState.OrderChecked).OnExit(
  procedure
  begin
    GetCommandeFournisseur;
  end
).Permitif(TWarehouseCheckInTrigger.SetProduct,
  TWarehouseCheckInState.ProductChecked,IsProductValid );

FState.Configure(TWarehouseCheckInState.ProductChecked)
  .PermitReentryif(TWarehouseCheckInTrigger.AddCarton,IsNeverAdded);

FState.Configure(TWarehouseCheckInState.CartonAdded).OnEntry(
  procedure
  begin
    if ProductNotAdded(FScannedBarCode) then
      AddProduct(TProduct.Create(FScannedBarCode));
  end
);

Here is how I'm using my class:

WarehouseCheckIn := TWarehouseCheckIn.Create;
WarehouseCheckIn.State.OnTransitioned(WarehouseCheckInTransitioned);

WarehouseCheckIn.Order := '49469';
WarehouseCheckIn.State.Fire(TWarehouseCheckInTrigger.SetOrder);
WarehouseCheckIn.Product := 'F0055';
WarehouseCheckIn.State.Fire(TWarehouseCheckInTrigger.SetProduct);

WarehouseCheckIn.ScanedBarCode := '1';
WarehouseCheckIn.State.Fire(TWarehouseCheckInTrigger.AddCarton);
WarehouseCheckIn.ScanedBarCode := '2';
WarehouseCheckIn.State.Fire(TWarehouseCheckInTrigger.AddCarton);
WarehouseCheckIn.ScanedBarCode := '3';
WarehouseCheckIn.State.Fire(TWarehouseCheckInTrigger.AddCarton);
WarehouseCheckIn.ScanedBarCode := '1';
WarehouseCheckIn.State.Fire(TWarehouseCheckInTrigger.AddCarton); /* <=== should throw an exception because '1' was previously added */

I have mainly two problems:

  1. OnEntry events are never fired.

  2. I don't know how to add multiple conditions to the "AddCarton" state (check that carton was never added AND check that there is remaining carton to be picked).

This looks pretty simple, but I don't know how to achieve it.

0

There are 0 answers