[fpc-pascal] assigning ansistring with shortstring

Arne Hanssen nite at tuxic.net
Sat May 27 09:46:19 CEST 2006


L505 wrote:
> I'm lacking some memory concept here. Below program doesn't work unless setlengths
> are called first on the shortstrings.
> 
>   setlength(last3, 3);
>   last3[1]:= filename[length(filename)-2];
>   last3[2]:= filename[length(filename)-1];
>   last3[3]:= 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[0]:=chr(3);'.

-- 
Vennlig hilsen / Best regards      |\     ___,,--,        _
Arne Hanssen, Senja, Norway        /,`--''        \-,,__,'/
http://www.tuxic.net/             |,4   ) )_    ) /~-----'
---------------------------------'---^~(_/-_)--(_/_)-------



More information about the fpc-pascal mailing list