[fpc-pascal] assigning ansistring with shortstring

2006-05-26 Thread L505
I'm lacking some memory concept here. Below program doesn't work unless setlengths are called first on the shortstrings. program Project1; {$mode objfpc}{$H+} var filename: string; last3: string[3]; last4: string[4]; begin filename:= 'test'; filename:= filename+ 'ing.pas'; setlength

Re: [fpc-pascal] assigning ansistring with shortstring

2006-05-26 Thread DarekM
L505 napisaƂ(a): I'm lacking some memory concept here. Below program doesn't work unless setlengths are called first on the shortstrings. program Project1; {$mode objfpc}{$H+} var filename: string; last3: string[3]; last4: string[4]; this is not short strings use last3: shortstring[

Re: [fpc-pascal] assigning ansistring with shortstring

2006-05-26 Thread Jonas Maebe
On 26 May 2006, at 14:10, L505 wrote: I'm lacking some memory concept here. Below program doesn't work unless setlengths are called first on the shortstrings. program Project1; {$mode objfpc}{$H+} var filename: string; last3: string[3]; last4: string[4]; begin filename:= 'test';

Re: [fpc-pascal] assigning ansistring with shortstring

2006-05-26 Thread L505
> > I'm lacking some memory concept here. Below program doesn't work > > unless setlengths > > are called first on the shortstrings. > > > > program Project1; > > > > {$mode objfpc}{$H+} > > > > var > > filename: string; > > last3: string[3]; > > last4: string[4]; > > begin > > filename:= '

Re: [fpc-pascal] assigning ansistring with shortstring

2006-05-26 Thread L505
> > var > > filename: string; > > last3: string[3]; > > last4: string[4]; > > > this is not short strings > use > last3: shortstring[3]; In delphi 5 and FPC in objfpc mode it doesn't accept that. ___ fpc-pascal maillist - fpc-pascal@lists.fre

Re: [fpc-pascal] assigning ansistring with shortstring

2006-05-26 Thread Jonas Maebe
On 26 May 2006, at 19:35, L505 wrote: The length bytes of those shortstrings aren't initialised if you don't do setlength(). It has nothing to do with memory allocation, but with initialisation. Learn something new today - I unfortunately don't have a turbopascal background and in this case

Re: [fpc-pascal] assigning ansistring with shortstring

2006-05-27 Thread Arne Hanssen
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)]

Re: [fpc-pascal] assigning ansistring with shortstring

2006-05-27 Thread Jonas Maebe
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 "

Re: [fpc-pascal] assigning ansistring with shortstring

2006-05-27 Thread L505
> 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 > > al

Re: [fpc-pascal] assigning ansistring with shortstring

2006-05-28 Thread Jonas Maebe
On 27 May 2006, at 21:54, L505 wrote: 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) I didn't think the compiler would let you