unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);
var txtfile:TextFile;
begin
if savedialog1.Execute then
begin
Assignfile(txtfile,savedialog1.FileName);
Rewrite(txtfile);
writeln(txtfile,memo1.text);
closefile(txtfile);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
txtfile:TextFile;
str : string;
begin
     if opendialog1.Execute then
     Assignfile(txtfile,opendialog1.FileName);
     Reset(txtfile);
     while not Eof (txtfile)   do
     begin
          readln(txtfile,str);
          memo1.Lines.add(str);
     end;
     closefile(txtfile);
end;

end.
