
- •12.Списки
- •Interface
- •Implementation
- •13.Модули
- •Interface
- •Implementation
- •Interface
- •Implementation
- •Interface
- •Implementation
- •14.Таблицы
- •Interface
- •Implementation
- •15.Графика, отображение графиков функций
- •Interface
- •Implementation
- •Initialization
- •16.Графика, примитивы
- •Interface
- •Implementation
- •Interface
- •Implementation
- •Interface
- •Implementation
- •Initialization
- •17.Графика, растровые изображения и анимация
- •Interface
- •Implementation
- •Initialization
- •Interface
- •Implementation
- •18.Тестирование и отладка
- •19.Квадратное уравнение
- •Interface
- •20.Класс tThread
- •Interface
- •Implementation
- •Interface
- •Implementation
- •Interface
- •Implementation
- •21.Класс tStream
- •Interface
- •Implementation
- •Initialization
- •Interface
- •Implementation
- •Initialization
- •22.Создание в Delphi кроссплатформенного приложения
Interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
Memo2: TMemo;
Label1: TLabel;
Label2: TLabel;
Button3: TButton;
Memo3: TMemo;
Memo4: TMemo;
Label3: TLabel;
Label4: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Stream1,Stream2,Stream3,Stream4:TFileStream;
MyDir,MyFile1,MyFile2,MyFile3,MyFile4:string;
Implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Stream1:=TFileStream.Create(MyFile1,fmOpenRead);
Stream2:=TFileStream.Create(MyFile2,fmOpenRead);
Stream3:=TFileStream.Create(MyFile3,fmCreate);
Stream4:=TFileStream.Create(MyFile4,fmCreate);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Stream1.Seek(0,soFromBeginning);
Stream2.Seek(0,soFromBeginning);
Stream3.Seek(0,soFromBeginning);
Stream3.CopyFrom(Stream1,Stream1.Size);
Stream3.CopyFrom(Stream2,Stream2.Size);
Stream1.Seek(0,soFromBeginning);
Stream2.Seek(0,soFromBeginning);
Stream4.Seek(0,soFromBeginning);
Stream4.CopyFrom(Stream2,Stream2.Size);
Stream4.CopyFrom(Stream1,Stream1.Size);
Stream1.Free;
Stream2.Free;
Stream3.Free;
Stream4.Free;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Memo1.Lines.LoadFromFile(MyFile1);
Memo2.Lines.LoadFromFile(MyFile2);
Memo3.Lines.LoadFromFile(MyFile3);
Memo4.Lines.LoadFromFile(MyFile4);
end;
Initialization
MyDir:='d:\Eddy\21_1\';
MyFile1:=MyDir+'MyFile1.txt';
MyFile2:=MyDir+'MyFile2.txt';
MyFile3:=MyDir+'MyFile3.txt';
MyFile4:=MyDir+'MyFile4.txt';
end.
показано окно приложения задания 1 при исполнении программы. Видно, что данные файлов MyFile1 и MyFile2 объединяются в файлах MyFile3 и MyFile4 в разном порядке.
рис. 21.9. Окно приложения задания 1 при исполнении программы
Задание 2
Для работы с потоками в памяти создаем приложение, форма которого представлена на рис. 21 .10. Файлы проекта будем сохранять в папке 21_2. Для формы определим надпись «Класс TMemoryStream». Форма отличается от формы задания 1 надписями на кнопках. В проекте создаем 2 потока в памяти класса TMemoryStream для приема данных из существующих файлов MyFile1 и MyFile2, а также два файловых потока класса TFileStream для новых файлов MyFile3 и MyFile4. Файл MyFile3 = MyFile1 + MyFile2, а файл MyFile4 = MyFile2 + MyFile1. Предварительно файлы MyFile1 и MyFile2 нужно скопировать в папку проекта. Проект – приложение.
рис. 21.10. Форма задания 2 на стадии конструирования
Листинг модуля формы
unit Prg_21_2_;
Interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
Memo2: TMemo;
Label1: TLabel;
Label2: TLabel;
Button3: TButton;
Memo3: TMemo;
Memo4: TMemo;
Label3: TLabel;
Label4: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Stream1,Stream2:TMemoryStream;
Stream3,Stream4:TFileStream;
MyDir,MyFile1,MyFile2,MyFile3,MyFile4:string;