[fpc-pascal] Calling a function by name (as string) read from a text file

Daniël Mantione daniel.mantione at freepascal.org
Wed Oct 10 12:36:05 CEST 2007



Op Wed, 10 Oct 2007, schreef Jilani Khaldi:

> {////////////////////////////////////////////////
> Is there a way to "connect" the name of the function as a string "evoke" to
> the true function "evokeFun: SetupFun;" getting a new function
> "newEvokeFun: SetupFun;" so I can write:
> ////////////////////////////////////////////////}

Create a table with function names and the actual function, for example:

type  Tsetupfunc_mapping=record
        name:string;
        func:setupfunc;
      end;
  
const setupfunc_mapping:array[0..2] of Tsetupfunc_mapping=(
       (name:'setup_function_1';func:@setup_function_1),
       (name:'setup_function_2';func:@setup_function_2),
       (name:'setup_function_3';func:@setup_function_3));

Then search the name of the function you want to call in the table, then 
call the function in the "func" field.

Daniël


More information about the fpc-pascal mailing list