Selecting What Data to Show
Go Up to Designing the User Interface
Often, the data you want to surface in your database application does not correspond exactly to the data in a single database table. You may want to use only a subset of the fields or a subset of the records in a table. You may want to combine the information from more than one table into a single joined view.
The data available to your database application is controlled by your choice of dataset component. Datasets abstract the properties and methods of a database table, so that you do not need to make major alterations depending on whether the data is stored in a database table or derived from one or more tables in the database. For more information on the common properties and methods of datasets, see Understanding Datasets.
Your application can contain more than one dataset. Each dataset represents a logical table. By using datasets, your application logic is buffered from restructuring of the physical tables in your databases. You might need to alter the type of dataset component, or the way it specifies the data it contains, but the rest of your user interface can continue to work without alteration.
You can use any of the following types of dataset:
- Table components: Tables (
TIBTable) correspond directly to the underlying tables in the database. You can adjust which fields appear (including adding lookup fields and calculated fields) by using persistent field components. You can limit the records that appear using ranges or filters. Tables are described in more detail in Working with Tables. Persistent fields are described in “Persistent field components” in the Delphi Developer’s Guide. Ranges and filters are described in Working with a subset of data.
- Query components: Queries (
TIBSQL) provide the most general mechanism for specifying what appears in a dataset. You can combine the data from multiple tables using joins, and limit the fields and records that appear based on any criteria you can express in SQL. For more information on queries, see Working with Queries.
- Stored procedures: Stored procedures (
TIBStoredProc) are sets of SQL statements that are named and stored on an SQL server. If your database server defines a remote procedure that returns the dataset you want, you can use a stored procedure component. For more information on stored procedures, see Working with Stored Procedures.
- Client datasets: Client datasets cache the records of the logical dataset in memory. Because of that, they can only hold a limited number of records. Client datasets are populated with data in one of two ways: from an application server or flat-file data stored on disk. When using a client dataset to represent flat-file data, you must create the underlying table programmatically. For more information about client datasets, see Creating and using a client dataset in the Delphi Developer’s Guide.
- Custom datasets: You can create your custom descendants of
TDataSetto represent a body of data that you create or access in code you write. Writing custom datasets allows you the flexibility of managing the data using any method you choose while still letting you use the VCL data controls to build your user interface. For more information about creating custom components, see Overview of component creation in the Delphi Developer’s Guide.