Unit VFileU

This unit contains all the routines needed for handling files with variable length (up to 65528 bytes) records. Records are identified by positive longints and all of the routines refer to these numbers. The numbers do NOT indicate where the records are stored in the file. That information is in a seperate file maintained by these routines. To use any of the routines just drop a TVFile component on a form, set its FileName property and call AttachFile to use the routines. (See below for details). Use the Create Wizard to create a VFile data set.

Classes

TVFile -

Functions

Register - FileName: This is the name of a data set that contains the actual records.

Types

FreeList
FreeListPtr
LocItem

Constants

Variables


Functions


procedure Register;

FileName: This is the name of a data set that contains the actual records. There is also an auxiliary file with the same name prefixed with a underscore. This file contains the locations of the records and is consulted when records are fetched, inserted, deleted or restored. The data set must exixt on disk when this property is set since SetVFileName reads it to set some internal fields. BlockSiz: This is the size of each block. Read only. RecordCount: Just the number of records in the file. Read only. AttachFile: This method hooks up the internal TVFile with the disk data set named in the FileName property. It MUST be called before any other methods or they wont work. A good place to put this is in the OnCreate event for the form. DetachFile. This method need not be called unless you want to use the TVFile on another data set. This method breaks the connection between the data set and the TVFile. Here is an example. We wish to disconnect the TVFile from the data set 'DATA1' and connect instead to 'DATA2'. AVFile.DetachFile; -- disconnects DATA1 -- AVFile.FileName := 'DATA2'; AVFile.AttachFile; GetBufSize: This method gets the size of a buffer (in bytes) that will to hold the record with id rid. Exist: Returns TRUE if the record with record number rid exists. Fetch: This method gets the record with id rid and places it in the buffer pointed to by Buf. The buffer must be large enough to hold the record and this method will overwrite the buffer if it is not big enough. FALSE is returned if the record does not exist. Insert: This method is used to insert a new record with id rid. The record is stored is the buffer pointer to by Buf. The user must supply the record length in RL. This method checks to see that the id rid is not being used already, and if it is, returns FALSE and does nothing. Restore: This method is used to restore a fetched record. The id is rid. The user must supply the record length since the record may have changed size. This method checks to see that the id rid is being used already, and if it is not, returns FALSE and does nothing. Delete: This method is used to delete a record. The id is rid. This method check to see that the id rid is being used already, and if not, returns FALSE and does nothing.

Types


FreeList = array [0..0] of LocItem;

FreeListPtr = ^FreeList

LocItem = record
start : longint;
count : longint;
end;
Make sure these records are packed

Constants


Variables