why does the expression
Code: Select all
Ptr := ^const TStateTransition(Machine.TransitionTable);
while the expression
Code: Select all
Ptr := ^const TStateTransition(^const byte(Machine.TransitionTable));
Apparently 2 subsequent type castings are needed here?
The types used are:
Code: Select all
type
TGetEventProc = function: byte;
TActionProc = procedure(Id, From, Towards, Event: byte);
TStateTransition =
record
Fromstate, ToState, Event: byte;
Action: ^TActionProc;
end;
TStateMachineTable = array[1] of TStateTransition; // dummy size
TStateMachine =
record
Ident : byte;
TransitionTable : ^const TStateMachineTable;
NrTransitions : byte;
GetEventProc : ^TGetEventProc;
Running : boolean; // running or stopped
CurrentState : byte; // the current state of the state machine
CurrentEvent : byte; // the current event to react upon
NextState : byte; // the future state of the state machine
end;
Code: Select all
procedure StateMachine_Step(var Machine: TStateMachine);
var Index : byte;
Routine : ^TActionProc;
Ptr : ^const TStateTransition;
Found : boolean;
begin
....
Ptr := ^const TStateTransition(^const byte(Machine.TransitionTable)); // point to first entry in the State Transition table
...
end;