unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  szemadat=record
    nev:string[50];
    varos:string[80];
    ut:string[50];
    telefon:string[20];
    fizu:integer;
    torolt:boolean;
  end;



var
  Form1: TForm1;
  k:^szemadat;
  fp,i:integer;
  f:file of szemadat;
implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
begin
  new(k);
  assignfile(f,'adatok.dat');
  {$I-}
     reset(f);
  {$I+}
  if ioresult<>0 then
               rewrite(f);
  if filesize(f)>0 then
      begin
        read(f,k^);
        edit1.Text:=k^.nev;
        edit2.Text:=k^.varos;
        edit3.Text:=k^.ut;
        edit4.Text:=k^.telefon;
        edit5.Text:=inttostr(k^.fizu);
      end;
  fp:=0;    
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if (edit1.Text<>'') and (edit4.text<>'') then
       begin
         k^.nev:=edit1.text;
         k^.varos:=edit2.text;
         k^.ut:=edit3.text;
         k^.telefon:=edit4.text;
  if edit5.Text<>'' then k^.fizu:=strtoint(edit5.text)
                    else k^.fizu:=0;
         k^.torolt:=true;
       end
  else
    showmessage('A név és a telefonszám mezõket megkell adni');
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  seek(f,filesize(f));
  write(f,k^);
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  closefile(f);
  close;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
inc(fp);
if fp>filesize(f)-1 then
  begin
   showmessage('Az utolsó adatot látod');
   fp:=filesize(f)-1;
   end
                    else
                      begin
                        seek(f,fp);
                        read(f,k^);
                        edit1.Text:=k^.nev;
                        edit2.Text:=k^.varos;
                        edit3.Text:=k^.ut;
                        edit4.Text:=k^.telefon;
                        edit5.Text:=inttostr(k^.fizu);
                      end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
dec(fp);
if fp<0 then
   begin
     showmessage('Az elsõ adatot látod');
     fp:=0;
   end
                    else
                      begin
                        seek(f,fp);
                        read(f,k^);
                        edit1.Text:=k^.nev;
                        edit2.Text:=k^.varos;
                        edit3.Text:=k^.ut;
                        edit4.Text:=k^.telefon;
                        edit5.Text:=inttostr(k^.fizu);
                      end;

end;

procedure TForm1.Button7Click(Sender: TObject);
begin
   button1.Click;
   seek(f,fp);
   write(f,k^);
end;

end.
