На главную
Подписка
Новости


Рейтинг@Mail.ru











Главная / DELPHI / Часто задаваемые вопросы и ответы на них / Компоненты / Копирование файлов потоком Сделать домашней страницей Добавить в избранное Написать писмо

Копирование файлов потоком




unit MemoForm;

interface

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

type
  TForm1 = class(TForm)
    SaveDialog1: TSaveDialog;
    Memo1: TMemo;
    OpenDialog1: TOpenDialog;
    Panel1: TPanel;
    ButtonLoadMemo: TButton;
    ButtonSaveMemo: TButton;
    ButtonCopyFile: TButton;
    procedure ButtonSaveMemoClick(Sender: TObject);
    procedure ButtonLoadMemoClick(Sender: TObject);
    procedure ButtonCopyFileClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ButtonSaveMemoClick(Sender: TObject);
var
  MyStream: TFileStream;
begin
  if SaveDialog1.Execute then
  begin
    if FileExists (SaveDialog1.FileName) then
      MyStream := TFileStream.Create (
        SaveDialog1.FileName, fmOpenWrite)
    else
      MyStream := TFileStream.Create (
        SaveDialog1.FileName, fmOpenWrite or fmCreate);
    try
      Memo1.Lines.SaveToStream (MyStream);
    finally
      MyStream.Free;
    end;
  end;
end;

procedure TForm1.ButtonLoadMemoClick(Sender: TObject);
var
  MyStream: TFileStream;
begin
  if OpenDialog1.Execute then
  begin
    MyStream := TFileStream.Create (
      OpenDialog1.FileName, fmOpenRead);
    try
      Memo1.Lines.LoadFromStream (MyStream);
    finally
      MyStream.Free;
    end;
  end;
end;

procedure TForm1.ButtonCopyFileClick(Sender: TObject);
var
  Stream1, Stream2: TFileStream;
begin
  if OpenDialog1.Execute and SaveDialog1.Execute then
  begin
    Stream1 := TFileStream.Create (
      OpenDialog1.FileName, fmOpenRead);
    try
      Stream2 := TFileStream.Create (
        SaveDialog1.FileName, fmOpenWrite or fmCreate);
      try
        Stream2.CopyFrom (Stream1, Stream1.Size);
      finally
        Stream2.Free;
      end;
    finally
      Stream1.Free;
    end;
  end;
end;


end.

Загрузить весь проект


Copyright ©   "DELPHI WORLD"   E-mail:   delphiworld@mail.ru  http://www.delphiworld.narod.ru
Источник получения информации: http://www.delphiworld.narod.ru
Hosted by uCoz