unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Label3: TLabel;
    Edit3: TEdit;
    Button1: TButton;
    Memo1: TMemo;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    BitBtn1: TBitBtn;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

Type TClient=record
       FIO: string[50];
       Adress: string[50];
       Date: string[12];
     end;

var
  Client: array[1..100] of TClient;
  Fz: file of TClient;
  Ft: TextFile;
  n: integer;
  FileNameZ, FileNameT: string;

var
  Form1: TForm1;

implementation

{$R *.dfm}

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

procedure TForm1.Button1Click(Sender: TObject);
begin
  n:=n+1;
  with Client[n] do begin
    FIO:=Edit1.Text;
    Adress:=Edit2.Text;
    Date:=Edit3.Text;
    Memo1.Lines.Add(IntToStr(n)+'. '+FIO+' '+Adress+' '+Date);
  end;
  Write(fz,Client[n]);
  Edit1.Clear;
  Edit2.Clear;
  Edit3.Clear;
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);
    n:=0;
    while not EOF(Fz) do begin
      n:=n+1;
      Read(Fz,Client[n]);
      with Client[n] do Memo1.Lines.Add(IntToStr(n)+'. '+FIO+' '+Adress+' '+Date);
    end;
    Button1.Show;
  end;
end;

procedure TForm1.Button4Click(Sender: TObject);
var i: word;
begin
  if SaveDialog1.Execute then  begin
    FileNameT:=SaveDialog1.FileName;
    AssignFile(Ft,FileNameT);
    Rewrite(Ft);
    for i:=1 to n do with Client[i] do Writeln(Ft,i,'. ',FIO,' ',Adress,' ',Date);
    CloseFile(Ft);
  end;
end;

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

procedure TForm1.Button5Click(Sender: TObject);
var i,j,k: integer;
begin
  for i:=1 to n do
  for j:=1 to n do
    if ((Client[j].FIO=Client[i].FIO) and (j<>i)) or ((Client[j].Adress=Client[i].Adress) and (j<>i)) then begin
      for k:=j to n do Client[k]:=Client[k+1];
      n:=n-1;
    end;  
    Memo1.Clear;   
  for i:=1 to n do with Client[i] do Memo1.Lines.Add(IntToStr(i)+'. '+FIO+' '+Adress+' '+Date);  
end;

end.
