unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Memo1: TMemo;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit4: TEdit;
    Label4: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    BitBtn1: TBitBtn;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    Button5: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  Type
  trab=record
  FIO:string[40];
  Notd,Data:extended;
  Dol:string[30];
  end;
      var
      fz:file of trab;
      ft:TextFile;
      Rab:Array[1..100] of TRab;
      nzap:integer;
      fnz,fnt:string;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
edit1.text:='';
edit2.text:='';
edit3.text:='';
edit4.text:='';
memo1.Clear;
button1.Hide;
nzap:=0;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     nzap:=nzap+1;
     with rab[nzap] do
          begin
          fio:=edit1.Text;
          notd:=strtofloat(edit2.text);
          dol:=edit3.text;
          data:=strtofloat(edit4.text);
          memo1.Lines.Add(fio+'   '+floattostr(notd)+'   '+dol+'   '+floattostr(data));
          end;
  write(fz,rab[nzap]);
edit1.text:='';
edit2.text:='';
edit3.text:='';
edit4.text:='';

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
OpenDialog1.Title:='Создание';
    if opendialog1.Execute then
        begin
        fnz:=Opendialog1.FileName;
        assignfile(fz,fnz);
        rewrite(fz);
        end;
    button1.Show;

end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  if opendialog1.Execute then
     begin
     fnz:=opendialog1.FileName;
     assignfile(fz,fnz);
     reset(fz);
     end;
     while not eof(fz) do
           begin
           nzap:=nzap+1;
           read(fz,rab[nzap]);
         with rab[nzap] do
     memo1.Lines.Add(fio+'   '+floattostr(notd)+'   '+dol+'   '+floattostr(data));
       end;
       button1.Show;
end;

procedure TForm1.Button4Click(Sender: TObject);
var
i:word;
begin
  if savedialog1.Execute then
    begin
    fnt:=savedialog1.FileName;
    assignfile(ft,fnt);
    rewrite(ft);
    end;
    for i:=1 to nzap do
         with rab[i] do
         writeln(ft,i,fio,notd,dol,data);
         closefile(ft);

end;

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

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
closefile(fz);
end;

procedure TForm1.Button3Click(Sender: TObject);
var
 i,j:word;
 st:trab;
begin
   for i:=1 to nzap-1 do
   for j:=i+1 to nzap do
   if rab[i].data<rab[j].data then
        begin
        st:=rab[i];
        rab[i]:=rab[j];
        rab[j]:=st;
        end;
   memo1.clear;
   for i:=1 to nzap do
   with rab[i] do
   memo1.Lines.Add(inttostr(i)+fio+'   '+floattostr(notd)+'   '+dol+'   '+floattostr(data));


end;

end.
