Fields and Strings

Chapter Updated 2/1/99




The title of this chapter almost sounds like a popular North American magazine called Field and Stream. The difference between this chapter and that magazine is there are no dead animal carcuses or fishing lures in this chapter. For those you will need to get a copy of Field and Stream.

The main objective of this chapter is to provide information regarding the basic concepts of manipulating data via the field methods.

Field names can be up to ten bytes in length and can contain characters, numbers or special characters in the name. The field methods are used to manipulate the data in a record of a data file. There are several types of fields.

Field Types

TypeSizeAllowable ValuesSchema Value
Numeric0 - 17(include sign and decimal point+ - . 0 through 9XB_NUMERIC_FLD
Character0 - 254AnythingXB_CHAR_FLD
Date8CCYYMMDDXB_DATE_FLD
Floating Point0 - 17 (includes sign and decimal point+ - . 0 through 9XB_FLOAT_FLD
Logical1? Y y N n T t F f (? - uninitialized)XB_LOGICAL_FLD
MemoFixed length portion - 10
Variable length 0 - 32760
Type III - Text
Type IV - Anything
XB_MEMO_FLD


Field names, types and lengths are defined when a data file is created. After the file is created, the field characteristics can not be changed. To change field characteristics, a new database must be defined with the new field requirements.

Memo Fields

Memo fields are variable length data fields which are stored in two parts. This first part is a ten byte field which is stored in the fixed length record of the .DBF file. The variable data is stored in a seperate .DBT file in 512 byte blocks. The ten byte field in the fixed length portion of the record points to a .DBT block number.

There are two versions of memo data files type III and type IV. Type IV is more advanced in that released space can be reused and it also supports BLOB data. The type III file is older technology, does not support dynamic space reclamation and only supports string data. See method xbDbf::SetVersion for controlling which version type you are using.

To utilize memo fields, the application program must allocate a buffer which is large enough to handle the memo data.

Fields and Field Numbers

The Xbase routines can access field data via using field names or field numbers. Field numbers are numbered 0-n where the first field in a datafile is field 0 going through the last field n. Accessing fields by number is more efficient than accessing by name.

file, NextBlockNo and Version. Depending on the Xbase software, some vendors products update these two fields, some do not. The Xbase library keeps the fields updated, but does not rely on them to be valued with correct data. This helps to support maximum compatibility amoungst all Xbase tools available.

For version 4 memo field files, the first block in the .DBT file is a header block which is comprised of 8 bytes of data which maintain the file's block size and the next free block available in the file. Blocks two through n contain the actual memo data. A chain of empty blocks is maintained within the file for potential future use. When an add or update routine executes, it first attempts to find a spot in a set of blocks which were earlier allocated, but not currently in use for the data. If no free spot is found, data are appended to the end of the file. The free block chain is sorted in block number order. When blocks of data are freed and added to the free block chain, the routines will attempt to concatonate free block