Subject | Re: udf firebird delphi |
---|---|
Author | Steve Summers |
Post date | 2004-03-31T19:42:33Z |
--- In firebird-support@yahoogroups.com, Marc Collin <os2@v...> wrote:
"Crash" doesn't tell us anything. Crashing where? (BTW- do you have
range checking turned on? You might want to do so.)
> Steve Summers wrote:wrote:
>
> > --- In firebird-support@yahoogroups.com, Marc Collin <os2@v...>
> > > in delphi i use:the
> > >
> > > 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
> > length of your string- i.e., the position of the null thatterminates
> > it.0.
> >
> > You need to change your FOR loop to go from Length(Str)-1 downto
> >With "String" changed to PChar?
> >
> under delphi that crash...
"Crash" doesn't tell us anything. Crashing where? (BTW- do you have
range checking turned on? You might want to do so.)