자체 데이터베이스 만들기

4475 단어 데이터베이스
type
   TMember = record
     Name : string[50];
     eMail : string[30];
     Posts : LongInt;
   end;
 
  var Members : array[1..50] of TMember;
  var F : file of TMember;

 
write data
var
   F : file of TMember;
   i : integer;
 begin
  AssignFile(F,'members.dat') ;
  Rewrite(F) ;
  try
   for j:= 1 to 50 do
    Write (F, Members[j]) ;
  finally
   CloseFile(F) ;
  end;
 end;
read data
var
   Member: TMember
   F : file of TMember;
 begin
  AssignFile(F,'members.dat') ;
  Reset(F) ;
  try
   while not Eof(F) do begin
    Read (F, Member) ;
    {DoSomethingWithMember;}
   end;
  finally
   CloseFile(F) ;
  end;
 end;
 
seek and position
{go back to the beginning - the first record}
 Seek(F, 0) ;
 
 {go to the 5-th record}
 Seek(F, 5) ;
 
 {Jump to the end - "after"the last record}
 Seek(F, FileSize(F)) ;
 

change and update
procedure ChangeEMail(const RecN : integer; const NewEMail : string) ;
 var DummyMember : TMember;
 begin
  {assign, open, exception handling block}
  Seek(F, RecN) ;
  Read(F, DummyMember) ;
  DummyMember.Email := NewEMail;
  {read moves to the next record, we have to
  go back to the original record, then write}
  Seek(F, RecN) ;
  Write(F, DummyMember) ;
  {close file}
 end;

 

좋은 웹페이지 즐겨찾기