Консультация № 188286
30.11.2015, 21:10
0.00 руб.
0 1 0
Здравствуйте! У меня возникли сложности с таким вопросом:
Вот задание:
Даны символьные файлы f1 и f2. Переписать с сохранением порядка следования компоненты файлы f1 в файл f2, а компоненты файла f2 - в файл f1. Использовать вспомогательный файл.
Вот программа:
unit Unit1;

interface

uses
System, System.Drawing, System.Windows.Forms;

type
Form1 = class(Form)
procedure button1_Click(sender: Object; e: EventArgs);
procedure button2_Click(sender: Object; e: EventArgs);
procedure button3_Click(sender: Object; e: EventArgs);
{$region FormDesigner}
private
{$resource Unit1.Form1.resources}
button2: Button;
button3: Button;
button1: Button;
{$include Unit1.Form1.inc}
{$endregion FormDesigner}
public
constructor;
begin
InitializeComponent;
end;
end;

implementation

var
gpath: string;
gpath2: string;

procedure Form1.button1_Click(sender: Object; e: EventArgs);
var
open: System.Windows.Forms.OpenFileDialog;
error: boolean;
begin
gpath := '';
try
open := new OpenFileDialog();
if open.ShowDialog() = System.Windows.Forms.DialogResult.OK then
gpath := open.FileName;
except
MessageBox.Show('Не удалось открыть файл');
error := true;
end;
if error then exit;
end;

procedure Form1.button2_Click(sender: Object; e: EventArgs);
var
f, g: file of char;
i, j: integer;
x: char;
str: string;
error: boolean;
begin

str := 'aeiouy';
j := 0;
if (gpath = '') or (gpath2 = '') then messagebox.Show('Не был выбран один из файлов', 'Ошибка') else
begin
error := false;
try
Assign(f, gpath);
Reset(f);
except
MessageBox.Show('Error');
error := true;
end;
if error then exit;

try
Assign(g, gpath2);
rewrite(g);
except
MessageBox.Show('Error');
error := true;
CloseFile(f);
end;
try
for i := 1 to FileSize(f) do
begin
read(f, x);
if str.Contains(x) then
begin
write(g, x);
end;
end;
finally
CloseFile(f);
CloseFile(g);
end;
end;
end;

procedure Form1.button3_Click(sender: Object; e: EventArgs);
var
open: System.Windows.Forms.OpenFileDialog;
begin
gpath2 := '';
try
open := new OpenFileDialog();
if open.ShowDialog() = System.Windows.Forms.DialogResult.OK then
gpath2 := open.FileName;
except
on System.IO.IOException do MessageBox.Show('Error');
end;
end;

end.



можете написать комментарии напротив каждой строки? не очень понимаю, что тут происходит...

Обсуждение

давно
Посетитель
399158
228
01.12.2015, 11:37
общий
можете помочь?
Форма ответа