unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Splitter1: TSplitter;
    Edit1: TEdit;
    Label1: TLabel;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Button1: TButton;
    Memo1: TMemo;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    BitBtn1: TBitBtn;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    Button5: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  Type
  TRadio=record
   Group:string[40];
   Marka:string[40];
   Data:string[40];
   Ready:string[40];
   end;
  var
    Fz : file of TRadio;
    Ft : TextFile;
    Stud : array[1..100] of TRadio;
    nzap : integer;
    FileNameZ, FileNameT : string;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  nzap:=nzap+1;
  with stud[nzap] do begin
   Group:=Edit1.Text;
   Marka:=Edit2.Text;
   Data:=Edit3.Text;
   Ready:=Edit4.Text;
   Memo1.Lines.Add(Group+' '+Marka+' '+Data+' '+Ready);
         end;
Write(fz,Stud[nzap]);
Edit1.Clear; Edit2.Clear; Edit3.Clear; Edit4.Clear;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    Edit1.Clear; Edit2.Clear; Edit3.Clear; Edit4.Clear;
    Memo1.Clear;
    Button1.Hide;
    nzap:=0;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  OpenDialog1.Title :='Создать новый файл';
  if OpenDialog1.Execute then
  begin
  FileNameZ:= OpenDialog1.FileName;
  AssignFile(Fz, FileNameZ);
  Rewrite(Fz);
end;
  Button1.Show;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
  FileNameZ:= OpenDialog1.FileName;
  AssignFile(Fz, FileNameZ);
  Reset(Fz);
  end;
  nzap:=0;
  while not eof(fz) do begin
   nzap:=nzap+1;
    Read(fz,stud[nzap]);
    with stud[nzap] do
     Memo1.Lines.Add(Group+' '+Marka+' '+ Data+' '+Ready);
         end;	
         Button1.Show;
end;

procedure TForm1.Button4Click(Sender: TObject);
  var i,j : word;
begin
  for i:=1 to nzap-1 do
  for j:=i+1 to nzap do
  Memo1.Clear;
  for i:=1 to nzap do
  with stud[i] do
Memo1.Lines.Add(IntToStr(i)+' '+Group+' '+Marka+' '+Data+' '+Ready);
end;

procedure TForm1.Button5Click(Sender: TObject);
var i:word;
begin
if SaveDialog1.Execute then
begin
FileNameT:= SaveDialog1.FileName;
AssignFile(Ft, FileNameT);
Rewrite(Ft);
end;
for i:=1 to nzap do
with stud[i] do Writeln(Ft,i:4,'. ',Group,Marka,Data,Ready);
CloseFile(Ft);
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  CloseFile(fz);
end;

end.
