Subject | Re: [firebird-support] udf firebird delphi |
---|---|
Author | Marc Collin |
Post date | 2004-03-31T18:04:55Z |
Martijn Tonies wrote:
What is the length of
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
> Hi Marc,for allo, that return 4... it's ok
>
> 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?
What is the length of
> a PChar in Delphi? According to the Help:have remove it...
> 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?
>
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,http://pages.infinit.net/borland
>
> Martijn Tonies
> Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
> Server.
> Upscene Productions
> http://www.upscene.com