RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.StrDispose Function

Disposes of a string.

Pascal
procedure StrDispose(Str: PAnsiChar); overload;
procedure StrDispose(Str: PWideChar); overload;
C++
StrDispose(PAnsiChar Str);
StrDispose(PWideChar Str);

StrDispose is provided for backward compatibility. StrDispose disposes of a string on a heap that was previously allocated with StrAlloc or StrNew.  

If Str is nil (Delphi) or NULL (C++), StrDispose does nothing.  

C++ Examples: 

 

/*
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.t_str());
  Application->MessageBox(
    Edit1->Text.c_str(),
    L"StrNew, StrDispose example",
    MB_OK);
  // Deallocate memory.
  StrDispose(psz);
}

 

Delphi Examples: 

{
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.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  Temp: PChar;
begin
  // Allocate memory.
  Temp := StrNew(PChar(Edit1.Text));
  Application.MessageBox(Temp, 'StrNew, StrDispose example', MB_OK);
  // Deallocate memory.
  SysUtils.StrDispose(Temp);
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!