Subject Re: [firebird-support] UDF By Reference
Author Svein Erling Tysvaer
Hi!

I know virtually nothing about writing UDFs, but I'm very happy that
your expectations aren't true! Suppose you had a statement like:

SELECT GetIntValue(a.ID)
FROM MyTable a

Would you expect the ID column of MyTable to be increased by one for
every record (i.e. turn the SELECT into a disguised UPDATE)? Far from
it, it should only be the returned value (the output) from the function
that can be affected by the function, what you pass into it should be
for input only.

So I hope that Firebird treats all UDFs as if they were called by value
(though I don't know whether Fb actually does this).

Set

redtneen wrote:
> Hi
>
> I wrote UDF in Delphi and tried this function
>
> function tcbGetIntValue(vValue: PInteger): PInteger; cdecl; export;
> begin
> ResultInteger := vValue^ * 2;
> Result := @ResultInteger;
> vValue^ := vValue^ + 1;
> end;
>
> it's declaration
>
> declare external function GetIntValue
> integer
> returns
> integer
> entry_point 'tcbGetIntValue' module_name 'tcbReportsUDF.dll';
>
> then i tried this statement
>
> execute block
> returns
> (
> res integer
> )
> as
> declare variable val integer;
> begin
> res = 10;
> val = GetIntValue(res);
> suspend;
> res = val;
> suspend;
> end
>
> Result is:
>
> Res
> 10
> 20
>
> i expected to be
> Res
> 11
> 20
>
> because all input parameters in UDF are calling by Reference
> can any one help me to understand this point ??????
>
> my regards