Function Pointers

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Function Pointers

Brent Smith-4
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 
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Function Pointers

Burkhard Carstens-3
Am Donnerstag, 7. September 2006 15:02 schrieb 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;
[snip]
This syntax only works in {$mode delphi} ..
try "PtrToFunc := @TestPtr2;" instead.

regards

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal