Subject RE: [ib-support] UDF Problems
Author Gerhardus Geldenhuis
Thanks I sorted out the problem. Part of the problem was that as you say
pchars should not be a var parameter. Secondly I used trimleft and not trim
on my strings in the procedure and this bugged me round a lot and I blaymed
it on the paramters.
Btw If you cast a pchar like this mystring:=string(a_pchar) then the cast
fills the rest of the string with spaces.
I am thinking of writing a small something on everything I learned during my
hunt for problems it should be of help for others starting out.

Groete
Gerhardus

> -----Original Message-----
> From: Doug Chamberlin [mailto:dchamberlin@...]
> Sent: 13 September 2001 22:02
> To: ib-support@yahoogroups.com
> Subject: RE: [ib-support] UDF Problems
>
>
> At 9/13/2001 04:51 AM (Thursday), Gerhardus Geldenhuis wrote:
> >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.
>
> If all IB passes are pointers to arguments then all your parameter
> declarations must be pointers. The easiest way to handle this is
> to declare
> them as "var". However, declaring them as non-var types should also 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.
>
> The declarations of Operation and CalcType look suspicious to me. As they
> are above they are declared as "pointer to pointer to char". That may not
> match what is being passed.
>
> Here is the declaration from a UDF I just dung up from my archives:
> function DLA_LOWER(pStr: PChar): PChar; cdecl; export;
>
> This function receives a string argument and returns a string argument.
>
> Here's how it is declared in the database:
> DECLARE EXTERNAL FUNCTION LOWER CSTRING(255)
> RETURNS CSTRING(255)
> ENTRY_POINT "DLA_LOWER"
> MODULE_NAME "DLAUDF";
>
> So, I would conclude that you should use "var" for the non-string
> parameters and remove it from the string params.
>
>
>
> To unsubscribe from this group, send an email to:
> ib-support-unsubscribe@egroups.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>