[fpc-pascal] Firebird UDF

Stephano patspiper at yahoo.com
Thu Mar 13 18:28:05 CET 2008


Codebue Fabio - P-Soft wrote:
> This is my UDF source 
> 
> library pudf; 
>   {$mode objfpc}{$H+} 
> uses 
>   Classes; 
> 
> function pround(var valore: real; ndec: integer):real;export; 
> var 
>   i: integer; 
>   risultato: real; 
>   ndivisore: integer; 
> begin 
>   risultato:= valore; 
>   ndivisore:= 1; 
>   for i:= 1 to ndec do 
>   begin 
>     risultato:= risultato*10; 
>     ndivisore:= ndivisore*10; 
>   end; 
>   result:= round(risultato)/ndivisore; 
> end; 
> 
> exports 
>   pround name 'pround'; 
> 
> begin 
> end. 
> 
> but after insert into my fdb with instruction 
> 
> DECLARE EXTERNAL FUNCTION pround 
> DOUBLE PRECISION, INTEGER 
> RETURNS DOUBLE PRECISION BY VALUE 
> ENTRY_POINT 'pround' MODULE_NAME 'pudf'; 
> 
> if I use it with an instruction like this 
> 
> select round(123.1233, 2) as nrounded from rdb$database 
> 
> I have back this error 
> 
> Invalid token. 
> invalid request BLR at offset 59. 
> function PROUND is not defined. 
> module name or entrypoint could not be found. 
> 
> do you have some idea regarding this error?

1- You should use cdecl for your function

2- you should use pudf_pround as module entry name

3- use double instead of real

I hope this helps.



More information about the fpc-pascal mailing list