home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / w3_prog / db3tpwun.arj / DB3DEMUN.PAS < prev    next >
Pascal/Delphi Source File  |  1991-09-12  |  2KB  |  69 lines

  1. { Simple program to test the DB3 unit DBase file open functions }
  2. { Requires db3.tpu in current directory                         }
  3. { Written by Nigel Salt 1991 - apologies for PASCAL it is not   }
  4. {                              my first language!               }
  5. PROGRAM db3demun;
  6. USES db3,WinCRT;
  7.  
  8.  
  9. {************************}
  10. { MAIN BODY }
  11. {************************}
  12.  
  13. VAR
  14.    testdb: dbfRecord;
  15.    testdbflds: ARRAY[1..3] OF _FieldRecord;
  16.    testdbfldptr: _dFields;
  17.    testdbdata: String;
  18. BEGIN
  19.   {Set up fields}
  20.   testdbfldptr:=@testdbflds;
  21.   testdbflds[1].Name:= 'CUSTOMER';
  22.   testdbflds[1].Typ := 'C';
  23.   testdbflds[1].Len := 20;
  24.   testdbflds[1].Dec := 0;
  25.   testdbflds[1].Off := 1;
  26.  
  27.   testdbflds[2].Name:= 'DATE';
  28.   testdbflds[2].Typ := 'D';
  29.   testdbflds[2].Len := 8;
  30.   testdbflds[2].Dec := 0;
  31.   testdbflds[2].Off := 21;
  32.  
  33.   testdbflds[3].Name:= 'AMOUNT';
  34.   testdbflds[3].Typ := 'N';
  35.   testdbflds[3].Len := 16;
  36.   testdbflds[3].Dec := 2;
  37.   testdbflds[3].Off := 29;
  38.  
  39.   {Create a new database}
  40.   CreateDbf(testdb, 'dbintst.dbf', 3, @testdbflds[1]);
  41.  
  42.   {Append 3 records}
  43.   {Deleted record flag preceeds each rec so copy to CurRecord^[1]
  44.    testdata is astring so copy from testdata[1]}
  45.               {012345678901234567890123456789012345678901234}
  46.   testdbdata:='ALPHA               19910801-100.11         ';
  47.   Move(testdbdata[1],testdb.CurRecord^[1],44);
  48.   AppendDbf(testdb);
  49.   testdbdata:='BETA                199108022000.22         ';
  50.   Move(testdbdata[1],testdb.CurRecord^[1],44);
  51.   AppendDbf(testdb);
  52.   testdbdata:='GAMMA               19910803330             ';
  53.   Move(testdbdata[1],testdb.CurRecord^[1],44);
  54.   AppendDbf(testdb);
  55.   CloseDbf(testdb);
  56.  
  57.   {Now open and read the three records that were created}
  58.   testdb.FileName:='dbintst.dbf';
  59.   OpenDbf(testdb);
  60.   IF dbfError<>0 THEN WriteDBError
  61.   ELSE
  62.     BEGIN
  63.     WriteDBFormat(testdb);
  64.     WriteDBRec(testdb,1);
  65.     WriteDBRec(testdb,2);
  66.     WriteDBRec(testdb,3);
  67.     END;
  68.   CloseDbf(testdb);
  69. END.