[fpc-pascal] length for long ansistring = segment fault

Jonas Maebe jonas.maebe at elis.ugent.be
Mon Dec 3 11:43:27 CET 2012


On 03 Dec 2012, at 11:13, Michael Van Canneyt wrote:

> On Mon, 3 Dec 2012, ik wrote:
>
>> var
>> s : AnsiString;
>> l : word;
>>
>> begin
>> SetLength(s, 1024);
>> FillChar(s, 1024, '*');
>
> You are overwriting the pointer. S is (behind the scenes) a pointer  
> to a memory area. You should do FillChar(s[1], 1024, '*');

Or use http://www.freepascal.org/docs-html/rtl/system/stringofchar.html


Jonas



More information about the fpc-pascal mailing list