unit StrDispose;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// BeginExample: StrDispose
// Routine: SysUtils.StrDispose
// Routine: SysUtils.StrNew

// BeginCode
{
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;
// EndCode
// EndExample: StrDispose
end.
