Home Strange StrPCopy() AV error and workaround that does not seems to make sense
 I am running into a strange problem dealing with StrPCopy(). Please take a look at the sample codes below: procedure TForm2.butnTestClick(Sender: TObject); var s : string; begin //-- assign string this way will cause AV when trying to StrPCopy() s := 'original string'; //-- assign string this way works!!!!!!! //s := Trim('original string'); //-- AV error when trying to alter the string StrPCopy(PChar(s), PChar('changed')); //-- should come back with "changed" Memo1.Lines.Add(s); end;  I am using Delphi 10 Seattle. If I try to alter "s" using StrPCopy() I will get AV error. However, I surround my string declaration with Trim(), it will work. Seems like by surrounding string declaration with Trim() triggers compiler to turn off some sort optimization on that particular string. I just don't know what that is. Please help.