Subject Re: Help with UDF functions
Author Photios Loupis (4T)
Hi

I have many grey hairs from going down the road of developing my own
UDF library (mostly because of my impatience). I am not a expert on
this subject at all but I have loaded a ZIP file of a library that
works for us under extreme loads (1000+ inserts per minute sustained
for 5-8 hours). Some of the functions in the library are not used
anymore (for obvious reasons - have a look). The library
demonstrates string (to a large degree) and date manipulation (to a
small degree). Ihave had every conceivable problem whilst building
this library and now it seems to 'behave'. The file is described as

Firebird UDF Example Source Code

If anyone has any suggestions on improving the source code (not
removing ridiculous/obsolete functions) then please feel free to
email me. Remember this library was written in my early introduction
to this GREAT database system!

One SMALL thing to remember using this library, all functions that
return STRING data types must be declared in the UDF as By Reference
(FREE_IT).... VERY IMPORTATANT!!

Hope it helps....

--- In firebird-support@yahoogroups.com, "sllimr7139"
<_rmcontrols@m...> 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.
>
> Any help would be appreciated.
>
> Ryan