Subject Re: [firebird-support] udf firebird delphi
Author Marc Collin
Martijn Tonies wrote:
> Hi Marc,
>
> I'm not an expert on writing UDFs at all... but:
>
>
> > i created this function:
> >
> > function MixStr(Str:PChar):PChar;
>
> What's the declaration you're using? cdecl?
>
> > var
> > i, j : Integer;
> > c1 : Char;
> > begin
> > if (Str = nil) then
> > result := nil
> > else
> > begin
> > for i:=Length(Str) downto 1 do
>
> What does Length(Str) return?
for allo, that return 4... it's ok

What is the length of
> a PChar in Delphi? According to the Help:
> function Length(S): Integer;
> S is a string- or array-valued expression.
>
> > begin
> > j:=Random(i)+1;
> > c1:=Str[i];
> > Str[i]:=Str[j];
> > Str[j]:=c1;
> > end;
> > result := Str;
> > end;
> > end;
> >
> > under firebirdi declared:
> >
> > Declare external function f_MixStr cstring(64)
> > returns cstring(64) free_it
> > entry_point 'MixStr' module_name 'brudflib2.dll';
>
> As you're not grabbing any memory, should you use
> FREE_IT?
>
have remove it...


function MixStr(Str:PChar):PChar;cdecl; export;
var
i, j : Integer;
c1 : Char;
begin
if (Str = nil) then
result := nil
else
begin
for i:=Length(Str) downto 1 do
begin
j:=Random(i)+1;
c1:=Str[i];
Str[i]:=Str[j];
Str[j]:=c1;
end;
result := Str;
end;
end;

drop external function f_MixStr;
Declare external function f_MixStr cstring(64)
returns cstring(64)
entry_point 'MixStr' module_name 'brudflib2.dll';

select f_MixStr('allo') from rdb$database;


sometime that return a, sometime al, sometime la, sometime lla, sometime
llao...
return not all letter

> With regards,
>
> Martijn Tonies
> Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
> Server.
> Upscene Productions
> http://www.upscene.com

http://pages.infinit.net/borland