home *** CD-ROM | disk | FTP | other *** search
- TPASCAL for Windows DBase 2 and 3 read / write unit
- ===================================================
-
- Based on Routines published by James Troutman in 1986
- Rewritten as Turbo PASCAL for Windows unit by Nigel Salt 1991
-
- MANIFEST
- ========
- db3tpwun.doc this document
- db3.tpu Turbo PASCAL unit for DB3 functions
- db3demun.pas Simple demo of the DB3 unit
- db3demun.exe
-
- UNIT DECLARATIONS
- =================
-
- CONST
- MAX_HEADER = 4129; { maximum length of dBASE III header }
- MAX_BYTES_IN_RECORD = 4000; { dBASE III record limit }
- MAX_FIELDS_IN_RECORD = 128; { dBASE III field limit }
- BYTES_IN_MEMO_RECORD = 512; { dBASE III memo field record size }
-
- { Valid field types }
- ValidTypes : SET OF Char = ['C', 'N', 'L', 'M', 'D'];
-
- { Special Error codes for .DBF files }
- NOT_DB_FILE = $80; { first byte was not a $3 or $83 or a $2 (dBASE II)}
- INVALID_FIELD = $81; { invalid field type was found }
- REC_TOO_HIGH = $82; { tried to read a record beyond the correct range }
- PARTIAL_READ = $83; { only a partial record was read }
-
- TYPE
- _Str64 = STRING[64];
- _HeaderType = ARRAY[0..MAX_HEADER] OF Byte;
- _FieldDescType = ARRAY[0..31] OF Byte;
- _dRec = ^_DataRecord;
- _DataRecord = ARRAY[0..MAX_BYTES_IN_RECORD] OF Byte;
- _HeaderPrologType = ARRAY[0..31] OF Byte;
- _dbfFile = FILE;
-
- _FieldRecord = RECORD
- Name : String[10];
- Typ : Char;
- Len : Byte;
- Dec : Byte;
- Off : Integer;
- END;
-
- _FieldArray = ARRAY[1..MAX_FIELDS_IN_RECORD] OF _FieldRecord;
- _dFields = ^_FieldArray;
- _MemoRecord = ARRAY[1..BYTES_IN_MEMO_RECORD] OF Byte;
- _MemoFile = FILE OF _MemoRecord;
- _StatusType = (NotOpen, NotUpdated, Updated);
-
- dbfRecord = RECORD
- FileName : String[64];
- dFile : _dbfFile;
- HeadProlog : _HeaderPrologType;
- dStatus : _StatusType;
- WithMemo : Boolean;
- DateOfUpdate : String[8];
- NumRecs : Longint;
- HeadLen : Integer;
- RecLen : Integer;
- NumFields : Integer;
- Fields : _dFields;
- CurRecord : _dRec;
- END;
-
- VAR
- { See special error codes in INTERFACE CONST }
- dbfError: Integer; {Global error code}
- dbfOK: Boolean;
-
- PROCEDURE WriteDBError;
- {Writes text version of dbferror}
- PROCEDURE WriteDBFormat(D: dbfRecord);
- {Writes file and filed information}
- PROCEDURE WriteDBRec(D: dbfRecord; RecNum: Longint);
- {Writes one record}
- PROCEDURE GetDbfRecord(VAR D : dbfRecord; RecNum : Longint);
- {Gets one record to buffer}
- PROCEDURE PutDbfRecord(VAR D : dbfRecord; RecNum : Longint);
- {Puts one record in file}
- PROCEDURE AppendDbf(VAR D : dbfRecord);
- {Appends one record to end of file}
- PROCEDURE CloseDbf(VAR D : dbfRecord);
- {Closes a database}
- PROCEDURE OpenDbf(VAR D : dbfRecord);
- {Opens a databse}
- PROCEDURE CreateDbf(VAR D: dbfRecord; filename: _Str64; numfields: Integer;
- fldarrayptr : _dFields);
- {
- Call CreateDbf with the full pathname of the file that you want
- to create (filename), the number of fields in a record (numfields),
- and a pointer to an array of _FieldRecord (fldarrayptr). The procedure
- will initialize all the data structures in the dbfRecord (D).
- }
- ============================================================================
-
- As always all comments and contributions gratefuly received
-
- Nigel Salt
- 25 Lower Station Rd
- Crayford
- Kent
- DA1 3PY
-
- Phone 0322 553260
-
- CIX ID nao@cix.complink.co.uk
- RAX Nigel Salt on node 2:440/52.49
-
-