Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Thank you again! I can't tell you how much I and my company appreciate what you've done! I love this place!..."

Geography

Where in the world do Tek-Tips members come from?

freeing TStrings GetText buffer

deyzel (Programmer)
25 Apr 01 14:46
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
DoNotEven (Programmer)
19 Jun 01 23:24
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);
}

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close