Subject RE: [firebird-support] UDF Problem
Author Kevin Day Programming
>Tried your suggestions and get same disconnect result!! What do you think?
>library strudf;
> SysUtils;
>function fn_ProperCaseString(var szSource, szResult : PChar): PChar;
>cdecl; export;
> i : integer;
> len : integer;
> result := szResult;
> if strlen(szSource) = 0 then
> begin
> szResult^ := #0;
> exit;
> end;
> len := strlen(szSource);
> i := 0;
> szSource[i] := UpCase(szSource[i]); {Catch the first letter and
>uppercase it}
> while (i < len) do
> begin
> szResult^ := szSource^;
> while (szResult[i] <> ' ') and (i < Len) do
> begin
> inc(i);
> inc(szResult);
> szResult^ := szSource^;
> end;
> inc(i);
> inc(szResult);

{*** need to check here again for end of string - could be a part of the
if (i < Len) then
> szSource[i] := UpCase(szSource[i]); {Catch the next first letter
>uppercase it}
szResult^ := #0;
> end;
> fn_ProperCaseString;

Also I assume you are declaring it within firbird such as

ENTRY_POINT 'fn_ProperCaseString' MODULE_NAME 'strudf';

Also be sure to check that the string you are passing is <= to the declared
length - 80 in this case.

Finally if the IDE you are using for this piece of code allows I suggest you
trace through it. If you put a break point on the first line and check that
the input parameter holds what is expected. If it doesn't you know straight
away you've got a problem with your declarations or calling mechanism. From
code snippets I've seen both stdcall and cdecl in use, although I use cdecl.

To debug a dll in delphi (and I assume kylix) you tell it what the host
application is. For testing / debugging, install a copy of
interbase/firebird on your local development computer. I use super server
so I set the host application to be fbserver.exe (or ibserver.exe). Making
sure that firebird wasn't previously running (shut the service down if
running as an application). Run the dll from within delphi and the server
will be launched in application mode under delphi control. Log in to a
local database using ibconsole or whatever program and execute your test
query. Delphi will stop at the breakpoint and you can take a look at what
is happening.

Hope this helps.

Kevin Day