freeing TStrings GetText buffer
freeing TStrings GetText buffer
(OP)
The help on TStrings GetText says the caller needs to free the returned buffer. I have a memory checker that complains that I don't free the buffer.
char *tmpname;
tmpname = Msg->Lines->GetText();
... manipulate text...
free(tmpname);
What am I doing wrong??
Thanks
Deyzel
char *tmpname;
tmpname = Msg->Lines->GetText();
... manipulate text...
free(tmpname);
What am I doing wrong??
Thanks
Deyzel
RE: freeing TStrings GetText buffer
virtual char * __fastcall GetText(void);
Description
Call GetText to obtain a dynamically allocated character buffer containing all of the strings in the list. Individual strings are separated by a carriage return and line feed. The caller is responsible for freeing the returned value using the StrDispose procedure.
This example uses an edit control and a button on a form. When the button is clicked, memory is allocated for a copy of the text in the edit control, the text is displayed in a message box, and then the memory is deallocated.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// Allocate memory.
char* psz = StrNew(Edit1->Text.c_str());
Application->MessageBox(psz, "StrNew, StrDispose Example", MB_OK);
// Deallocate memory.
StrDispose(psz);
}