[fpc-pascal] assigning ansistring with shortstring

Jonas Maebe jonas.maebe at elis.ugent.be
Sat May 27 09:55:57 CEST 2006


On 27 May 2006, at 09:46, Arne Hanssen wrote:

>>   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);'.

Note that the setlength will generate exactly the same code as the  
'last3[0]:=chr(3);' statement, so it's better to keep the setlength  
(in case the string would ever become an ansistring, or just for  
readability)


Jonas



More information about the fpc-pascal mailing list