Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-09

Function Pointers

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Brent Smith

I am trying to use function/procedure pointers with the FPC version 2.0.2 on Windows 2000. The complete test program is given below. The error is "Wrong
number of parameters specified". When I put this into Delphi 5 then it works no problem and prints 25 as expected. Any suggestions or is this a current
limitation of the compiler?

Thanks,

Brent Smith

***** Program: *****

program TestPtrs;

uses
SysUtils

type
  IntFunc = function (Num: Integer) : Integer;
var
  PtrToFunc : IntFunc;
  x : Integer;
{ Multiply by five. }
function TestPtr2(Num: Integer): Integer;
begin
   TestPtr2 := 5 * Num ;
end;
begin
  x := 5;
  {
     Error: Wrong number of parameters specified
    Hint: Found declaration:TestPtr2(LongInt):LongInt
    TestPtrs.pas(34, stopping
  }
  PtrToFunc := TestPtr2;
  writeln(PtrToFunc(x));
  readln;
end.

__________________________________________________ Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

Burkhard Carstens
to Brent Smith
Brent Smith wrote 40 lines
I am trying to use function/procedure pointers with the FPC version 2.0.2 on Windows 2000. The complete test program is given below. The error is "Wrong number of parameters specified". When I put this into Delphi 5 then it works no problem and prints 25 as expected. Any suggestions or is this a current limitation of the compiler? Thanks, Brent Smith ***** Program: ***** program TestPtrs; uses SysUtils type IntFunc = function (Num: Integer) : Integer; var PtrToFunc : IntFunc; x : Integer; { Multiply by five. } function TestPtr2(Num: Integer): Integer; begin TestPtr2 := 5 * Num ; end; begin x := 5; { Error: Wrong number of parameters specified Hint: Found declaration:TestPtr2(LongInt):LongInt TestPtrs.pas(34, stopping } PtrToFunc := TestPtr2;

[snip]
This syntax only works in {$mode delphi} ..
try "PtrToFunc := @TestPtr2;" instead.

regards