unit Unit_18;

interface

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

type
  TForm1 = class(TForm)
    SaveDialog1: TSaveDialog;
    RichEdit1: TRichEdit;
    RichEdit2: TRichEdit;
    Button1: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
//---------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
var
   stream: TMemoryStream;
begin
  // tworzy i inicjuje strumien stream
  stream  := TMemoryStream.Create;
  // zawartosc RichEdit1 zapisuje do strumienia
  RichEdit1.Lines.SaveToStream(stream);
  // ustawia sie na poczatku strumienia
  stream.Position := 0;
  // zawartosc strumienia zapisuje do RichEdit2
  RichEdit2.Lines.LoadFromStream(stream);
  // a nastepnie na dysk
  if (SaveDialog1.Execute()) then
     RichEdit2.Lines.SaveToFile(SaveDialog1.FileName);
  // usuwa strumien z pamieci
  stream.Free;
end;
//---------------------------------------------------------
procedure TForm1.Button3Click(Sender: TObject);
begin
  Application.Terminate();
end;
//---------------------------------------------------------
end.
