Board index » delphi » Needed: Code for array of pointers to procedures

Needed: Code for array of pointers to procedures

I need example code of using an unbound array that contains pointers to
procedures. Similar to the following C code snippet extracted from
Libero (FSM from http:\\www.imatix.com) generated code.

static dbyte _LR_vector [][3+1] =
{
    {0},
    {0,_LR_STOP},
    {6,_LR_STOP},
    {2,0,_LR_STOP},
    {5,0,_LR_STOP},
    {3,2,0,_LR_STOP},
    {4,6,_LR_STOP},
    {1,0,_LR_STOP}

Quote
};

static fsmfunct *_LR_module [] =
{
    get_char_from_input,
    other_if_nested_comment,
    put_char_to_output,
    put_slash_to_output,
    signal_unterminated_comment,
    start_new_comment,
    terminate_the_program

Quote
};

 for (;;)
          {
            if ((*_LR_vecptr == _LR_STOP)
            || (exception_raised))
                break;
            (*_LR_module [*_LR_vecptr++]) ();
 

Re:Needed: Code for array of pointers to procedures


"Gregory B. Brooks" <brooks.g...@worldnet.att.net> wrote:

Quote
>I need example code of using an unbound array that contains pointers to
>procedures. Similar to the following C code snippet extracted from
>Libero (FSM from http:\\www.imatix.com) generated code.
>static dbyte _LR_vector [][3+1] =
>{
>    {0},
>    {0,_LR_STOP},
>    {6,_LR_STOP},
>    {2,0,_LR_STOP},
>    {5,0,_LR_STOP},
>    {3,2,0,_LR_STOP},
>    {4,6,_LR_STOP},
>    {1,0,_LR_STOP}
>};
>static fsmfunct *_LR_module [] =
>{
>    get_char_from_input,
>    other_if_nested_comment,
>    put_char_to_output,
>    put_slash_to_output,
>    signal_unterminated_comment,
>    start_new_comment,
>    terminate_the_program
>};
> for (;;)
>          {
>            if ((*_LR_vecptr == _LR_STOP)
>            || (exception_raised))
>                break;
>            (*_LR_module [*_LR_vecptr++]) ();

The main problem is unbound array - the rest is simple

type
  TActionProc = Procedure;
  TActionList = Array[0..0] of TActionProc;
  PActionList = ^TActionList;

const
  LRModule : PActionList = nil;

begin
  ...
{ allocate mem for 30 elements }
  GetMem( LRModule, 30 * sizeof( TActionProc);
  ...
{$R-} { Must have }
  LRModule^[LR_vectptr];
{$R+}
  ...
end;

IMHO should work, but I didn't try...

Cheers
  Dmitri

--------------------------------------------------------------
        Shit happens, but why it always happens to us?
--------------------------------------------------------------
Dmitri Poujlivyi            mailto:  dmi...@god.bel.alcatel.be
                            http://www.dma.be/p/bewoner/dmitri

Other Threads