TCB4Table Info

TCB4Table is a wrapper around CodeBase that can be used as a BDE replacement for a TTable. The focus during developing this component is on keeping it as compatible as possible with Borland's TTable. Which has as major advantages that you can easily migrate to or from the BDE or an other BDE replacement.

Of course TCB4Table is a descendant of TDataset so it can be used by any standard Delphi or third party control using a TDataset. Or in other words: you can use it wherever you normally would use a TTable.

How compatible TCB4Table is with TTable follows:

Compatible with TTable

procedure ApplyRange;
function BookmarkValid(Bookmark: TBookmark): Boolean;
CompareBookmarks(Bookmark1, Bookmark2: TBookmark): Integer;
procedure CancelRange;
procedure CloseIndexFile(const IndexFileName: string);
function CreateBlobStream(Field: TField; Mode: TBlobStreamMode): TStream;
procedure CreateTable; - (More info)
procedure DeleteTable;
procedure EditKey;
procedure EditRangeEnd;
procedure EditRangeStart;
procedure EmptyTable;
function FindKey(const KeyValues: array of const): Boolean;
procedure FindNearest(const KeyValues: array of const);
function GetCurrentRecord(Buffer: PChar): Boolean;
procedure GetIndexInfo;
procedure GetIndexNames(List: TStrings);
procedure GotoCurrent(Table: TCB4Table);
function GotoKey: Boolean;
procedure GotoNearest;
function IsSequenced: Boolean;
procedure OpenIndexFile(const IndexName: string);
function Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean;
function Lookup(const KeyFields: string; const KeyValues: Variant; const ResultFields: string): Variant;
procedure Post;
procedure SetKey;
procedure SetRange(const StartValues, EndValues: array of const);
procedure SetRangeEnd;
procedure SetRangeStart;
function Translate(Src, Dest: PChar; ToOem: Boolean): Integer;

property Active: Boolean;
property AfterCancel;
property AfterClose;
property AfterDelete;
property AfterEdit;
property AfterInsert;
property AfterOpen;
property AfterPost;
property AfterScroll;
property AutoCalcFields: Boolean;
property BeforeCancel;
property BeforeClose;
property BeforeDelete;
property BeforeEdit;
property BeforeInsert;
property BeforeOpen;
property BeforePost;
property BeforeScroll;
CacheBlobs: Boolean;
property CanModify: Boolean;
property Exclusive: Boolean;
property Exists: Boolean;
ExpIndex: Boolean;
property FieldDefs;
property Filtered;
property IndexDefs: TIndexDefs;
property IndexFieldCount: Integer
property IndexFieldNames: string
property IndexFields[Index: Integer]: TField
property IndexFiles: TStrings
property IndexName: string
property KeyExclusive: Boolean
property KeySize: Word
property MasterFields: string;
property MasterSource: TDataSource;
property ReadOnly: Boolean
property RecNo: Integer
property RecordCount: Integer
property Recordsize: Word
property StoreDefs: Boolean; // not in Delphi 3!
property TableName: string

And ofcourse everything inherited from TDataSet

Different from TTable

property Database: TCB4Database; - type is TCB4Database i.s.o. TDatabase
property DatabaseName: string
property Filter - uses dBase Expressions

Extra in TCB4Table

function CreateStringFilterText(const aFieldName: string; aFieldValue: string; aFieldLength: Integer): string;
Creates the text for usage in a filter where the Field should have a specified value. It takes care of quotes and filling out with spaces.

Example: CreateStringFilterText('FieldName', 'He searches "quotes"!', FieldLength(Field))
Results in the text for a filter that can be used to show only the records that have FieldName filled with the value 'He searches "quotes"!'. 

function FieldLength(Field: TField): Integer;
Get physical length of field

function GetFieldDataRaw(aField: TField; aBuffer: Pointer; aLength: Integer): Boolean;
Get the raw data of a Field copied into a Buffer. See also the help on GetFieldData.

procedure SetFieldDataRaw(aField: TField; aBuffer: Pointer; aLength: Integer);
Sets the raw data of a field copied from the aBuffer. See also GetFieldDataRaw.

Example: A string assigning to a field:

F := CB4Table.FieldByName('FieldName');
S := StringOfChar(' ', CB4Table.FieldLength(F));
CB4Table.SetFieldDataRaw(F, Pointer(S), Length(S));

property CBDATA4: DATA4;
Pointer to Codebase data

property IndexPaths[Index: Integer]: string;
The complete paths of the used indexfiles (-1 is productionindex)

property Options: TCB4TableOptions;
The following options are available:

property TablePath: string;
Complete path of table

Not implemented (yet) in TCB4Table

procedure AddIndex(const Name, Fields: string; Options: TIndexOptions; const DescFields: string = '');
procedure ApplyUpdates;
BatchMove(ASource: TBDEDataSet; AMode: TBatchMode): Longint;
procedure CancelUpdates;
CheckOpen(Status: DBIResult): Boolean;
procedure CloseDatabase(Database: TDatabase);
procedure CommitUpdates;
ConstraintCallBack(Req: DsInfoReq; var ADataSources: DataSources): DBIResult;
function ConstraintsDisabled: Boolean;
DeleteIndex(const Name: string);
procedure DisableConstraints;
procedure EnableConstraints;
procedure FetchAll;
procedure FlushBuffers;
procedure GetDetailLinkFields(MasterFields, DetailFields: TList);
procedure GetProviderAttributes(List: TList);
procedure LockTable(LockType: TLockType);
function OpenDatabase: TDatabase;
procedure RenameTable(const NewTableName: string);
procedure RevertRecord;
procedure UnlockTable(LockType: TLockType);
function UpdateStatus: TUpdateStatus;

property CachedUpdates: Boolean;
property DBHandle: HDBIDB;
property DBLocale: TLocale;
property DBSession: TSession;
property FilterOptions
property Handle: HDBICur;
property KeyFieldCount: Integer;
property Locale: TLocale;
property TableLevel: Integer;
property Constraints;
property DefaultIndex: Boolean;
property ObjectView;
property Provider;
property SessionName: string;
property TableType: TTableType;
property UpdateMode;
property UpdateObject;
property UpdatesPending: Boolean;
property UpdateRecordTypes;

property OnUpdateError;
property OnUpdateRecord;

Creating tables

You can create tables from within CB4 Tables using the CreateTable function, however you don't have much influence on what kind of fields and what their sizes should be with this function: It uses the same translations from FieldDefs in Delphi to Physical Fields in the table as the BDE does. Therefore it is recommended that you use the lowlevel CodeBase functions (d4create, i4create) to create tables.

Recognize tag expressions

From version 1.20 on, a new option is added to TCB4Table.Options: toRecognizeTagExpressions. If you turn this option on, CB4 Tables will parse expressions used in indexes to see how it is build up from fields. This is very useful if you are using expressions to concatenate fields: Locate and lookup functions can then use these indexes to perform a search.

The following constructions are recognized:

So if you have: STR(ID, 10, 0) + UPPER(NAME), it will be recognized as an index on the fields ID; NAME and as being case insensitive.


© MMIV Tiriss