Subject Re: [firebird-support] Re: udf firebird delphi
Author Marc Collin
Steve Summers wrote:

> --- In firebird-support@yahoogroups.com, Marc Collin <os2@v...> wrote:
> > in delphi i use:
> >
> > Function TForm1.MixStr(Str:String):String;
> > var
> > i, j : Integer;
> > c1 : Char;
> > 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;
> >
> > but can't use that for udf...
> >
>
> In your UDF version, you're substituting PChar for Delphi Strings.
> You can't just do that. Delphi strings use 1 as the origin. PChars
> use 0, so Length(PCharStr) actually returns an index ONE BEYOND the
> length of your string- i.e., the position of the null that terminates
> it.
>
> You need to change your FOR loop to go from Length(Str)-1 downto 0.
>
>
under delphi that crash...