Студопедия
Случайная страница | ТОМ-1 | ТОМ-2 | ТОМ-3
АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатика
ИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханика
ОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторика
СоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансы
ХимияЧерчениеЭкологияЭкономикаЭлектроника

Creating a master-detail form

Читайте также:
  1. Calculations in Calc. Creating and Coping Formulas
  2. Creating a vector or matrix
  3. Creating an Example Diagram
  4. CREATING COMPETENT COMMUNICATION PLANS
  5. Creating Connectors with Oblique Segments
  6. Creating Connectors with Oblique Segments

In the following example, you will create a simple form in which the user can scroll through customer records, and display all orders for the current customer. Follow these steps to create this application:

1 Place two TTable, two TDataSource, and two TDBDataGrid components on a form.

2 Set the properties of the first TTable component as follows:

DatabaseName: DBDEMO (the alias for the directory with the MAST database).

TableName: CUSTOMER (the table containing customer records).

Name: CustTable (for ease-of-use).

3 Name the first TDataSource component “CustDataSource,” and set its Dataset property to “CustTable.” Set the DataSource property of DBGrid1 to “CustDataSource.” When you activate CustTable (by setting its Active property to True), the grid displays the data in the CUSTOMER table.

4 Analogously, set the properties of the second TTable component as follows:

DatabaseName: DBDEMO.

TableName: ORDERS (the table containing order records).

Name: OrdTable (for ease-of-use).

5 Name the second TDataSource component “OrdDataSource,” and set its Dataset property to “OrdTable.” Set the DataSource property of DBGrid2 to “OrdDataSource.” When you activate OrdTable (by setting its Active property to True), the grid displays the data in the ORDERS table.

6 Compile and run the application now. The form displays data from each table independently and should look something like this:

Figure 3.8 Sample form

 

7 The next step is to link the ORDERS table (the master table) to the CUSTOMER table (the detail table) so that the form displays only the orders placed by the current customer. To do this, exit the application, return to design mode, and set the MasterSource property of OrdTable to CustDataSource.

8 In the Object Inspector, click on the ellipsis button to the right of the MasterFields property of OrdTable. The Field Link Designer dialog box will open.

• In the Available Indexes field, choose ByCustNo to link the two tables by the CustNo field.

• Select CustNo in both the Detail Fields and Master Fields field lists.

• Click on the Add button to add this join condition. In the Joined Fields list, “CustNo -> CustNo” will appear.

• Choose OK to commit your selections and exit the Field Link Designer.

If you run the application now, you will see that the tables are linked together, and that when you move to a new record in the CUSTOMER table, you see only those records in the ORDERS table that belong to the current customer.

The MasterSource property specifies the TDataSource from which OrdTable will take its master column values. This limits the records it retrieves, based on the current record in CustTable. To do this, you must specify for OrdTable:

• The name of the column that links the two tables. The column must be present in each table, and must be identically named.

• The index of the column in the ORDERS table that will be linked to the CUSTOMER table.

In addition, you must ensure that the ORDERS table has an index on the CustNo field. Since it is a primary index, there is no need to specifically name it, and you can safely leave the IndexName field blank in both tables. However, if the table were linked through a secondary index, you must explicitly designate that index in the IndexName property.

In this example, the CUSTOMER table has a primary index on the CustNo column, so there is no need to specify the index name. However, the ORDERS table does not have a primary index on CustNo, so you must explicitly declare it in the IndexName property, in this case ByCustNo

 

Note You can also set the IndexFieldNames property to CustNo, and the correct index will be supplied for you.


Дата добавления: 2015-10-26; просмотров: 160 | Нарушение авторских прав


Читайте в этой же книге: ДИСКУССИЯ С БУДДИСТАМИ | ДИСКУССИЯ С УЧИТЕЛЯМИ | Using the FieldByName method |
<== предыдущая страница | следующая страница ==>
Data type mappings| Displaying multiple views of a table

mybiblioteka.su - 2015-2024 год. (0.006 сек.)