Using TTable (Procedure)
Go Up to How To Perform Database Procedures
TTable is a table-type dataset that represents all of the rows and columns of a single database table.
To use TTable
- Choose File > New > Windows VCL Application - Delphi.
- Associate the dataset with the database and session connections.
- Specify the table type for local tables and control read/write access to local tables.
- Specify a dBASE index file.
- Rename local tables.
- Import data from another table.
To associate a dataset with database and session connections
- From the BDE category of the Tool Palette, drag a TDatabase component to the form.
- Drag a TSession component to the form.
- To associate a BDE-enabled dataset with a database, in the Object Inspector, set the DatabaseName property of the TDatabase component. For a TDatabase component, the database name is the value of the DatabaseName property of the database component.
- Use the default session to control all database connections in your application.
- Set the SessionName property of the TSession component to associate your dataset with an explicitly created session component.
If you use a session component, the SessionName property of a dataset must match the SessionName property for the database component with which the dataset is associated.
To specify the TableType and control read/write access
- From the BDE category of the Tool Palette, drag a TTable component to the form.
- In the Object Inspector, set the TableType property if an application accesses Paradox, dBASE, FoxPro, or comma-delimited ASCII text tables. BDE uses the TableType property to determine the table's type.
- Set TableType to ttDefault if your local Paradox, dBASE, and ASCII text tables use the file extensions like, .DB, .DBF, and .TXT.
- For other extensions, set TableType to ttParadox for Paradox, ttDBase for dBASE, ttFoxPro for FoxPro, and ttASCII for comma-delimited ASCII text respectively.
- Set the table component's Exclusive property to True before opening the table to gain sole read/write access.
Note: If the table is already in use when you attempt to open it, exclusive access is not granted. You can attempt to set Exclusive on SQL tables, but some servers do not support exclusive table-level locking. Others may grant an exclusive lock, but permit other applications to read data from the table.
To specify a dBASE index file
- Set the IndexFiles property to the name of the non-production index file or list the files with a .NDX extension.
- Specify one index in the IndexName property to have it actively sorting the dataset.
- At design time, click the ellipsis button in the IndexFiles property. The Index Files editor opens.
- To add a non-production index file or file with .NDX extension, click the Add button in the Index Files dialog and select the file from the Open dialog.
Note: For each non-production index file or .NDX file, repeat Steps 3 and 4.
- After adding all desired indexes, click the OK button in the Index Files editor.
Note: To do steps 3-5 at run time, access the IndexFiles property using properties and methods of string lists.
To rename local tables
- To rename a Paradox or dBASE table at design time, right-click the table component. A drop-down context menu opens.
- From the context menu, select Rename Table.
- To rename a Paradox or dBASE table at run time, call the table's RenameTable method.
To import data from another table
- Use the BatchMove method of a table component to import data, copy, update, append records from another table into this table, or delete records from a table.
- Set the name of the table from which to import data, and a mode specification that determines which import operation to perform.