Function syntax


Posted by James on April 06, 2001 at 16:54:07:

I'd like to implement a function in Delphi that takes several parameters, and returns a single number as a result. The code for my function is shown below:

function Returndist(cspeed, fspeed, area, dragcoeff, downfcoeff, 
  gripcoeff, totcarweight :Double) :Double;
begin
  ....
  ....
  Result := dist;
end;

I have two questions though. Have I been correct in putting the funtion definition at the top of the unit Im working in, just underneath the definition for all my Procedures eg "Button2.click(Sender: TObject);"? The line of code I have is:

function Returndist(cspeed: Double; fspeed: Double; area: Double; dragcoeff: Double;
  downfcoeff: Double; gripcoeff: Double; totcarweight: Double) : Double;

Also, when I want to use this procedure, is the following valid syntax?

While (returndist(cspeed, fspeed, area, dragcoeff, downfcoeff,
  gripcoeff, totcarweight :Double) > distance) do 
  begin
  ...
  ...
  end;

At the moment Im getting errors like "Unsatisfied forward or exte rnal declaration". Im not used to programming in Delphi/Pascal, I wouldnt be having these problems If I was using C++ :)

Thanks for any sugestions
James


Related Articles and Replies: