Subject Re: udf firebird delphi
Author Steve Summers
--- In firebird-support@yahoogroups.com, Marc Collin <os2@v...> wrote:
> 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...

With "String" changed to PChar?

"Crash" doesn't tell us anything. Crashing where? (BTW- do you have
range checking turned on? You might want to do so.)