[fpc-pascal] Function Pointers

Burkhard Carstens fpc at bcsoft.de
Thu Sep 7 15:15:09 CEST 2006


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




More information about the fpc-pascal mailing list