Subject Re: [ib-support] UDF Problems
Author Doug Chamberlin
At 9/12/2001 05:38 AM (Wednesday), Gerhardus Geldenhuis wrote:
>If all parameters are passed by reference how come this code works in delphi
>it is extracted out of the freeudflib library.
>
>function DoubleAbs(var Value: Double): Double;
>begin
> result := Abs(Value);
>end;

The function DOES receive its parameter by reference. That is what the
"var" designation means. Without any such designation the parameter would
be passed by value (usually as a value on the stack).

Another way to receive a value by reference is to use a pointer as the
parameter and then de-reference it. The pointer, itself, would be passed by
value. An untested example of how to do it this way is below.

// The pointer type must be declared before its use...
type
DoublePtr: ^Double;

function DoubleAbs(ValuePtr: DoublePtr): Double;
begin
result := Abs(ValuePtr^);
end;

The use of "var" is recommended since this is usually how this is done in
Pascal. However, if you feel more comfortable using the C-like pointer
method, it should work.

Good luck!