Subject Re: [firebird-support] Help with UDF functions
Author Bogusław Brandys
sllimr7139 wrote:
>
> 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.

Maybe, but also try add var to all non PChar input parameters ;-)


Regards
Bogusław Brandys