I'm using custom windows messages to exchange information from the worker thread to the forms in the main VCL thread. Whenever I need to send some data with the message I do this:
type
PntStr = ^string;
then PostMessage()
var
pointString : PntStr;
(...)
New(pointString);
pointString^ := mystring;
PostMessage(frmDest.Handle, UM_THREADMSG, UM_MYEVENT1, LPARAM(pointString));
On the receiving form
try
myStrP := PntStr(MSG.LParam);
myfunction(myStrP^);
finally
Dispose(myStrP);
end;
Is this the correct way to deal with the memory allocated by the pointer? Does calling Dispose() on the pointer take care of freeing the memory?