TMedTable Properties Methods Events

TMedTable is a TMedDataset descendant.

Unit

MedDataset

Description

TMedTable component is similar in its functionality to BDE TTable component.

TMedTable component is used as an interface to DBF or Mediator tables. At a given moment one TMedTable instance can be used to acces one DBF or one Mediator table. After closing the old table, the new table can be opened using the same instance of TMedTable. TMedTable component can be used for the following purposes:

·Opening a given DBF or Mediator table for access in exclusive or shared mode

·Navigating through table records in both directions with or without index

·Creating expression or field indexes for the table

·Deleting, adding new and modifying existing table records

·Searching for the records satisfying specified criteria

·Setting filters to abtain only the records meeting specified condition

·Setting scopes on the index to select subrange of the table records

·Creating master-detail relationship to another TMedTable instance

·Accessing xHarbour kernel functions related to table operations

Instance initialization

At least three properties should be set right after instance creation and before opening (activating) the table. These are:

MedConnection - set it to previously created instance of the TMedConnection class

TableType - this property value determines which RDD driver will be used to open a table

TableName - set it to the name of the table you wish to open. You may include drive name and directory path.

When initial property values are set, open table by assigning true to its Active property. Make sure TMedConnection instance assigned to MedConnection property is connected before opening the table. When ready with the table, close it by assigning false to Active property.

Error handling

When working with TMedTable or TMedQuery components, two kind of exceptions can be reported. EMedDataSetError exception is rised if a problem was detected on the VCL component layer. Examine exception object ErrorCode property and ERR_DS_... constants defined in MedDataset.prg to learn more about this kind of errors. Another exception class is EHbError. EHbError exception is raised if the problem was detected in low level interface, most likely while interacting with xHarbour kernel. Both EMedConnectionError and EHbError are descendants of the EDatabaseError class.

Sample TMedTable initialization for DBF (NTX) file

var

cn: TMedConnection;

tab: TMedTable;

begin

// TMedConnection initialization here

// . . .

tab := TMedTable.Create(Nil);

tab.MedConnection := cn;

tab.TableType := ttDBFNTX; // use DBFNTX RDD driver (DBF files + NTX indexes)

tab.TableName := 'test.dbf';

try

tab.Active := true; // open table

except

writeln('Open failed');

Exit;

end;

// . . .

tab.Active := false; // close table

tab.Free;

end;

Sample TMedTable initialization for Mediator table

var

cn: TMedConnection;

tab: TMedTable;

begin

// TMedConnection initialization here

// . . .

tab := TMedTable.Create(Nil);

tab.MedConnection := cn;

tab.TableType := ttMEDNTX; // use MEDNTX Mediator RDD driver

tab.TableName := 'test.dbf';

try

tab.Active := true; // open table

except

writeln('Open failed');

Exit;

end;

// . . .

tab.Active := flase; // close table

tab.Free;

end;