Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

freeing TStrings GetText buffer

Status
Not open for further replies.

deyzel

Programmer
Apr 4, 2001
15
CA
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
 
Allocates a text buffer and fills it with the value of the Text property.

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);
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top