[fpc-pascal] assigning ansistring with shortstring
fpc505 at z505.com
Sat May 27 21:54:40 CEST 2006
> On 27 May 2006, at 09:46, Arne Hanssen wrote:
> >> setlength(last3, 3);
> >> last3:= filename[length(filename)-2];
> >> last3:= filename[length(filename)-1];
> >> last3:= filename[length(filename)];
> > As already explained, you must tell 'last3' its length. As you
> > already
> > are using a somewhat "lowlevel" approach, you could replace the state-
> > ment 'setlength(last3, 3);' with 'last3:=chr(3);'.
> Note that the setlength will generate exactly the same code as the
> 'last3:=chr(3);' statement, so it's better to keep the setlength
> (in case the string would ever become an ansistring, or just for
I didn't think the compiler would let you access string directly anyway, even with
range checking off - since that's a compiler thing - but I haven't checked for sure.
(using i:=0; string[i] could work but calling setlength is fine for me for this purpose).
More information about the fpc-pascal