unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    MainMemo: TMemo;
    ClearButton: TButton;
    procedure ClearButtonClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ClearButtonClick(Sender: TObject);
begin
 MainMemo.Lines.Clear;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 MainMemo.Lines.SaveToFile('memo.txt');
end;

procedure TForm1.FormShow(Sender: TObject);
begin
 if FileExists('memo.txt') then
  MainMemo.Lines.LoadFromFile('memo.txt');
end;

end.
