Subject Re: [firebird-support] Help with UDF functions
Author Ivan Prenosil
> function udf_CountSections(St: PChar; ParseSep: char) : integer;

> function udf_ParseSection(ParseLine: PChar; ParseNum: Integer;
> ParseSep: Char) : PChar;


You have to use cdecl calling convention,
you should use PChar instead of char,
and since all input parameters are passed by reference you should use
ParseNum: PInteger
(or var ParseNum: Integer)

Ivan
http://www.volny.cz/iprenosil/interbase/


----- Original Message -----
From: "sllimr7139" <_rmcontrols@...>
To: <firebird-support@yahoogroups.com>
Sent: Saturday, October 30, 2004 7:19 PM
Subject: [firebird-support] Help with UDF functions


>
>
> Hi all,
>
> I've got two functions that I rely on quite heavily in delphi and
> I'm now trying to make a UDF version of the them. I've got them
> compiling and loading in to FB1.5 but when ever I run them I always
> get an invalid result. Here are the actual functions can anyone
> see what I'm doing wrong with them? I've modified them from the
> original Pascal version (string -> pchar) but other than that
> they're pretty much exactly as I use them in one of my delphi apps.
>
> BTW, I've added them to the TBUDF project on my local machine and
> loaded them as a part of the TBUDF dll. The other functions from
> the TBUDF still work properly.
>
> function udf_CountSections(St: PChar; ParseSep: char) : integer;
> var
> iPos: LongInt;
> tmp : string;
> begin
> result := 0;
> if st = nil then
> exit;
> tmp := StrPas(St);
> while (tmp <> '') do
> begin
> iPos := Pos(ParseSep, tmp) ;
> if iPos > 0 then
> begin
> Delete(tmp, 1, iPos) ;
> inc(result) ;
> end
> else
> begin
> if tmp <> '' then
> begin
> inc(result) ;
> tmp := '';
> end;
> end;
> end;
> end;
>
> function udf_ParseSection(ParseLine: PChar; ParseNum: Integer;
> ParseSep: Char) : PChar;
> var
> iPos: LongInt;
> i: Integer;
> tmp: string;
> ParseCount:integer;
> begin
> result := ParseLine;
> tmp := StrPas(ParseLine);
> ParseCount := udf_CountSections(ParseLine, ParseSep);
> if ParseNum < ParseCount then
> begin
> for i := 1 to ParseNum do
> begin
> iPos := Pos(ParseSep, tmp) ;
> if iPos > 0 then
> begin
> if i = ParseNum then
> begin
> StrPCopy(ParseLine, Copy(tmp, 1, iPos - 1));
> Exit;
> end
> else
> begin
> Delete(tmp, 1, iPos) ;
> end;
> end
> else if ParseNum > i then
> begin
> StrPCopy(ParseLine, '');
> Exit;
> end
> else
> begin
> StrPCopy(ParseLine, Tmp);
> Exit;
> end;
> end;
> end
> else
> StrPCopy(ParseLine, '')
> end;
>
> I have a feeling that the problem lies with the STRPAS function
> call but I'm not totally positive.
>
> Any help would be appreciated.
>
> Ryan