typedfil.pas

来自「This is programing tutorial for people w」· PAS 代码 · 共 65 行

PAS
65 行
字号
{ A crude database recording }
uses crt;
type
   Temployee = record
                  name    : string[20];
                  address : string[40];
                  phone   : string[15];
                  age     : byte;
                  salary  : longint;
               end;

var
   F : file of Temployee;
   c : char;
   r : Temployee;
   s : string;
   n : integer;
begin
   clrscr;
   write('Input file name to record databases : '); readln(s);

   assign(F,s);           { Associate it }
   {$I-}
      reset(F);           { First, open it }
   {$I+}

   n:=IOResult;
   if n<>0 then           { If it's doesn't exist then }
   begin
      {$I-}
         rewrite(F);      { Create it    }
      {$I+}
      n:=IOResult;
      if n<>0 then
      begin
         writeln('Error creating file !'); halt;
      end;
   end
   else
   begin                  { If it exists then }
      n:=filesize(F);     { Calculate total record }
      seek(F,n);          { Move file pointer PAST the last record }
   end;

   repeat
      clrscr;
      writeln('File position : ',filepos(f));
      write('Name    = '); readln(r.name);     { Input data }
      write('Address = '); readln(r.address);
      write('Phone   = '); readln(r.phone);
      write('Age     = '); readln(r.age);
      write('Salary  = '); readln(r.salary);

      write(F,r);                 { Write data to file }

      write('Input data again (Y/N) ?');
      repeat
         c:=upcase(readkey);      { Ask user : Input again or not }
      until c in ['Y','N'];
      writeln(c);
   until c='N';

   close(F);
end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?