Class TVFile (unit VFileU)

Inherits from

TComponent

Constructors


constructor Create(AOwner: TComponent);

=============== TVFile methods =========================


Functions

procedure AttachFile;


function Delete(rid: longint): boolean;

now get a new one

destructor Destroy;


procedure DetachFile;

Assume the worst

function Exist(rid: longint): boolean;


function Fetch(rid: longint; Buf: pointer): boolean;


function GetBufSize(rid: longint): longint;

Suppose OK

function Insert(rid: longint; Buf: pointer; RL: longint): boolean;


function Restore(rid: longint; Buf: pointer; RL: longint): boolean;

insert into locator file

procedure AddToFreeList(GivenStart,GivenCount: longint);

Finds area in data file with room for BlocksWanted blocks and returns the block number where the area starts.

function FindArea(BlocksWanted: longint): longint;

Here we describe how the TVFile is built and how it works.

procedure SetBlockSize(Value: longint);


procedure SetVFileName(Value: string);

============= Set property routines ==================

Properties

property BlockSize : longint


property FileName : string


property RecordCount : longint


Events

Variables

BlockSiz : longint;


DataF : file;


FAttached : boolean;


FFileName : string;


FLP : FreeListPtr;


FreeCapacity : longint;


FreeCount : longint;


GenLI : LocItem;


LocF : file;


MaxCount : longint;


RecCount : longint;



Constructors


constructor Create(AOwner: TComponent);

=============== TVFile methods =========================


Functions


procedure AttachFile;


function Delete(rid: longint): boolean;

now get a new one


destructor Destroy;


procedure DetachFile;

Assume the worst


function Exist(rid: longint): boolean;


function Fetch(rid: longint; Buf: pointer): boolean;


function GetBufSize(rid: longint): longint;

Suppose OK


function Insert(rid: longint; Buf: pointer; RL: longint): boolean;


function Restore(rid: longint; Buf: pointer; RL: longint): boolean;

insert into locator file


procedure AddToFreeList(GivenStart,GivenCount: longint);

Finds area in data file with room for BlocksWanted blocks and returns the block number where the area starts.


function FindArea(BlocksWanted: longint): longint;

Here we describe how the TVFile is built and how it works. The TVFile is actually two files. The data file is a sequence of BlockSize byte blocks one after another, and the other file is a locator file. The locator file's name is the name used by the FileName property and the data file name has an extra '_' as first character. Records in the data file occupy groups of successive blocks called a group. Short records have just a few groups and long record have many groups. The locator file keeps track of the groups and what they contain. Except for the first 4 longints the locator file is just a long list of start/count pairs. The first longints are: RecCount: The number of records in the file. This number is incremented whenever a new record is inserted into the file and decremented whenever a record is deleted. BlockSiz: The number of bytes in a block. Set when the file was created and is never changed. FreeCapacity: The number of possible entries in the FreeList discussed below. FreeCount: The actual number of entries in the Free List. Set when the file is created or when COMPRESS runs. MaxCount: The actual number of entries that have ever been on the FreeList since the file was created or compressed. COMPRESS uses this to suggest a new value for FreeCapacity. Then there follows an array [1 .. FreeCapacity] of start/count pairs that form the free list. This is a list of places in the file that used to contain records but now those records have been deleted or moved. If the pair (4507,17) occurs in the free area, it means that blocks 4507-4523 are available for storage. A record as long as 17*BlockSize bytes could be stored there. When ever a new record is inserted or an old record must be moved because it has grown too long for its current block this list is consulted. If an existing free area is available it will be used to house the record and otherwise the file will be extended at its end. The pairs are kept is order of the start field so that abuting free areas can be ccombined. The number of entries in the free list is kept in the field FreeCount and can range from 0 to FreeCapacity. If there is no room to store a new item on the Free List the item is discarded. The COMPRESS utility reclaims these lost areas. Finally there is the list of start/count pairs that determine where the records are. For example, if (8305,9) is the pair with index 622 it means that record (622 - FreeCapacity-1) occupies blocks 8305-8313 at the present time. } {============= These routines are useful later ================


procedure SetBlockSize(Value: longint);


procedure SetVFileName(Value: string);

============= Set property routines ==================


Properties


property BlockSize : longint


property FileName : string


property RecordCount : longint


Events


Variables


BlockSiz : longint;


DataF : file;


FAttached : boolean;


FFileName : string;


FLP : FreeListPtr;


FreeCapacity : longint;


FreeCount : longint;


GenLI : LocItem;


LocF : file;


MaxCount : longint;


RecCount : longint;