[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 14:42:08 CEST 2007


y

Op Wed, 10 Oct 2007, schreef Jilani Khaldi:

> > 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.
> Thanks, but the consts should be:
> 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));
> 
> However compiling with {$mode objfpc} I get the error:
> ** Error: Some fields coming before "name" weren't initialized
> and it dosen't compile.

Did you implement the record exactly as shown? This error normally occurs 
if you have fields in your record that you don't mention in your typed 
const declaration.

Daniël


More information about the fpc-pascal mailing list