[fpc-pascal] PChar -> AnsiString -> PChar = memory leak?

Henry Vermaak henry.vermaak at gmail.com
Thu Oct 29 14:11:06 CET 2009


2009/10/29 Graeme Geldenhuys <graemeg.lists at gmail.com>:
> Hi,
>
> Do I create a memory leak if I cast a PChar it a AnsiString. Then
> append text to the AnsiString and then cast it back to the original
> PChar?
>
> eg:
> var
>  Text: Pchar;    <-- global var containing text.
>
> procedure AppendText(const AText: string);
> var
>  s: string;
> begin
>  s := Text + AText;
>  Text := PChar(s);
> end;

This will only work if you make s global, too...

Henry



More information about the fpc-pascal mailing list