Error: Wrong number of parameters specified for call to "f"

0

Witam, podczas kompilacji programu w lazarusie pojawia się błąd jak w tytule. Wyczytałem gdzieś, że to może być problem z flagą kompilatora, ale nie umiem go naprawić. Program główny pobiera funkcję z drugiego pliku, oto one:

 program project1;
uses Crt;
type vector = array [1..15] of Extended;
     fx     = function (x : Extended) : Extended;
var r, st     : Integer;
    a, b, eps : Extended;
{$I D:\STUDIA\Numeryczne\ROMBERG.PAS}

function f(x : Extended) : Extended; far;
begin
  f:=x*x
end;
{function f (x : Extended) : Extended; far;
begin
  f:=Sin(x/2)*Sin(x)/(17-8*Cos(x))
end;}
{function f (x : Extended) : Extended; far;
begin
  f:=1/(1+x*x)
end;}
begin
  ClrScr;
  Writeln ('* Romberg test *');
  Writeln;
  Write ('a = ');
  Readln (a);
  Write ('b = ');
  Readln (b);
  Write ('eps = ');
  Readln (eps);
  Write ('r (<=15 due to the definition of type "vector") = ');
  Readln (r);
  Writeln;
  Writeln ('Romberg (a, b, f, eps, r, st) = '); Romberg(a, b, f, eps, r, st));
  Writeln ('st = ', st);
  Readln
end.                        
function Romberg (a,b    : Extended;
                  f      : fx;
                  eps    : Extended;
                  r      : Integer;
                  var st : Integer) : Extended;
{---------------------------------------------------------------------------}
{                                                                           }
{  The function Romberg calculates an approximate value of the integral     }
{  from a function f(x) in a finite interval [a,b] by Romberg's method.     }
{  Data:                                                                    }
{    a,b - the ends of the intergration interval,                           }
{    f   - a Turbo Pascal function which for the given x calculates the     }
{          value of integrand f(x),                                         }
{    eps - accuracy for calculating the integral,                           }
{    r   - number of steps in Romberg's method.                             }
{          Note: It should be fulfilled the condition 2<=r<=15.             }
{  Result:                                                                  }
{    Romberg(a,b,f,eps,r,st) - approximate value of the integral.           }
{  Other parameters:                                                        }
{    st - a variable which within the function Romberg is assigned the      }
{         value of:                                                         }
{           1, if after r steps the given accuracy is not achieved,         }
{           2, if r<2 or r>15,                                              }
{           0, otherwise.                                                   }
{         Note: If st=1, then Romberg(a,b,f,eps,r,st) yields the last       }
{               approximation found, and if st=2 then the value of the      }
{               function Romberg is not calculated.                         }
{  Unlocal identifiers:                                                     }
{    vector - a type identifier of extended array [q1..qr], where q1<=1 and }
{             qr>=r,                                                        }
{    fx     - a procedural-type identifier defined as follows               }
{               type fx = function (x : Extended) : Extended;               }
{  Note: A function passed as a parameter should be declared with a far     }
{        directive or compiled in the $F+ state.                            }
{                                                                           }
{---------------------------------------------------------------------------}
var j,k,l        : Integer;
    h,h1,I,q,s,x : Extended;
    kon          : Boolean;
    t            : vector;
begin
  if (r>=2) and (r<=15)
    then begin
           t[1]:=0.5*(f(a)+f(b));
           h:=b-a;
           h1:=h;
           l:=1;
           k:=1;
           repeat
             k:=k+1;
             I:=t[1];
             s:=0;
             x:=a+0.5*h1;
             while x<b do
               begin
                 s:=s+f(x);
                 x:=x+h1
               end;
             h1:=0.5*h1;
             t[k]:=0.5*(t[k-1]+s/l);
             q:=1;
             for j:=k-1 downto 1 do
               begin
                 q:=4*q;
                 t[j]:=t[j+1]+(t[j+1]-t[j])/(q-1)
               end;
             kon:=abs(I-t[1])*h<=eps;
             if not kon
               then l:=2*l
           until kon or (k>=r);
           if kon
             then st:=0
             else st:=1;
           Romberg:=h*t[1]
         end
    else st:=2
end; 

Będę wdzięczny za rozwiązanie tego problemu.

1

Zobacz linię:

Writeln ('Romberg (a, b, f, eps, r, st) = '); Romberg(a, b, f, eps, r, st));

Przecież nie podałeś parametru wywołania funkcji fwięc komunikat błędu całkiem prawidłowy.</del>
A nie bu to przecież parametrem jest funkcja... hmmm
EDIT:
@urbi727 powinno być:

Writeln ('Romberg (a, b, f, eps, r, st) = '); Romberg(a, b, @f, eps, r, st);
0

Dokładnie tak jak napisał @kAzek - w odróżnieniu od Delphi, FPC wymaga podania wskaźnika na procedurę/funkcję/metodę, dlatego zawsze trzeba podać identyfikator poprzedzony symbolem @.

0

Śmiga, dzięki wielkie!

1 użytkowników online, w tym zalogowanych: 0, gości: 1