Subject | RE: [ib-support] UDF Problems |
---|---|
Author | Gerhardus Geldenhuis |
Post date | 2001-09-13T08:51:47Z |
> At 9/12/2001 05:38 AM (Wednesday), Gerhardus Geldenhuis wrote:Hi
> >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!
>
That was indeed the problem. There is something else that happens that is
also interesting.
If only some of your parameters is var then it does not work. All of them
must be var parameters in order for it to work. There is one problem piece
of code still left. Which causes the connection to be lost.
Here it is:
function CostPrice(var Width,Height,RF,WF:Integer;var CP:Double;var
Operation,CalcType:PChar):Double;
var
K:Double;
Op,CT:String;
begin
Op:=String(Operation);
Op:=TrimLeft(UpperCase(Op));
CT:=String(CalcType);
CT:=TrimLeft(UpperCase(CT));
...
If I comment out the conversion part then it works fine.
Thanks for the help so far.
Groete
Gerhardus