Hi All,

I have this program:

program mainfun;
{$mode objfpc}

uses
  SysUtils;

type
  SetupFun = function(const vect: array of double): double;

MyRec = record
  x: array of double;
  myFunName: ShortString; // function name to evoke
end;

function SetMeUp(const x1: array of double): double;
var
  i: integer;
  sum: double;
begin
  sum := 0.0;
  for i := 0 to High(x1) do
    sum := sum + x1[i];
  result := sum;
end;

// main
var
  MR: MyRec;
  y: double;
  st: string;
  f: text;
  i, count: integer;
  evokeFun: SetupFun;
begin
  // read MR from a text file...
  assign(f, 'data.txt');
  {$I-}
  reset(f);
  {$I+}
  readln(f, MR.myFunName);
  readln(f, count);
  setlength(MR.x,count+1);
  for i := 0 to count do
    readln(f, MR.x[i]);
  closefile(f);
  writeln(MR.myFunName);
  writeln(High(MR.x));
  for i := 0 to High(MR.x) do
    writeln(MR.x[i]);
{////////////////////////////////////////////////
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:
////////////////////////////////////////////////}
  newEvokeFun := @SetMeUp;
  y := newEvokeFun(MR.x);
  st := Format('Value: %6.5f', [y]);
  writeln(st);
  setlength(MR.x,0);
  readln;
end.
{
"data.txt" file contains:
evokeFun
1
 3.141590000000000E+000
 2.718280000000000E+000
}
I hope I have been clear in my request.
Thank you very much.

Jilani
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to