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

Michael Van Canneyt michael at freepascal.org
Mon Dec 3 11:13:40 CET 2012



On Mon, 3 Dec 2012, ik wrote:

> Hello,
>
> When I try to get the length of AnsiString, it returns me segment fault.
> I'm not sure if I'm doing something wrong:
>
> 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, '*');

Michael.



More information about the fpc-pascal mailing list