Do I need to allocate memory when performing a Delphi string copy?
I've a function which posts a Windows message to another form in my application. It looks something like this:
// Note: PThreadMessage = ^TThreadMessage; TThreadMessage = String;
function PostMyMessage( aStr : string );
var
gMsgPtr : PThreadMessage;
gStrLen : Integer;
begin
New(gMsgPtr);
gStrLen := StrLen(PWideChar(aMsg));
gMsgPtr^ := Copy(aMsg, 0, gStrLen);
PostMessage(ParentHandle, WM_LOGFILE, aLevel, Integer(gMsgPtr));
// Prevent Delphi from freeing this memory before consumed.
LParam(gMsgPtr) := 0;
end;