DBNavigator

Delphi

29/05/2003

Tenho um formAlterar, que trabalho com dados de duas tabelas, uma utilizo o código da tabela de Clientes e os demais campos utilizo a tabela de produtos, mas quando clico no navigator só muda um campo ou os dados de uma tabela, no caso a de cliente ou a de produto, coloquei dois navigator e clicando simultaneamente muda uma tabela e depois a outra, mas achei que nao ficou legal dois navigator, o que me sugere. Tem como ao clicar no navigator ele mostrar o codigo do cliente e ao mesmo tempo os produtos cadastrados a este cliente se algume souber e puder me ajudar, obrigado e aguardo uma resposta urgente.[quote:3076dd66dd][/quote:3076dd66dd]DELPHI1.

Meu e-mail: ma-silverio@bol.com.br


Delphi1

Delphi1

Curtidas 0

Respostas

Aroldo Zanela

Aroldo Zanela

29/05/2003

Colega,

O que você está precisando é fazer uma rotina Master/Detail, ou seja, quando você está navegando no registro mestre (pai) são exibidos somente os registros detalhes (filhos) daquele registro.

Os seguintes passos criam um formulário simples no qual um usuário pode rolar pelos registros de clientes e exibir todas os pedidos para o cliente atual. A tabela mestre é a CustomersTable, e a tabela de detalhe é OrdersTable.

1Place two TTable and two TDataSource components in a data module.
2Set the properties of the first TTable component as follows:

DatabaseName: DBDEMOS
TableName: CUSTOMER
Name: CustomersTable

3Set the properties of the second TTable component as follows:

DatabaseName: DBDEMOS
TableName: ORDERS
Name: OrdersTable

4Set the properties of the first TDataSource component as follows:

Name: CustSource
DataSet: CustomersTable

5Set the properties of the second TDataSource component as follows:

Name: OrdersSource
DataSet: OrdersTable

6Place two TDBGrid components on a form.
7Choose File|Include Unit Hdr to specify that the form should use the data module.
8Set the DataSource property of the first grid component to
“DataModule2->CustSource”, and set the DataSource property of the second grid to “DataModule2->OrdersSource”.
9Set the MasterSource property of OrdersTable to “CustSource”. This links the CUSTOMER table (the master table) to the ORDERS table (the detail table).

10Double-click the MasterFields property value box in the Object Inspector to invoke the Field Link Designer to set the following properties:

In the Available Indexes field, choose CustNo to link the two tables by the CustNo field.
Select CustNo in both the Detail Fields and Master Fields field lists.
Click the Add button to add this join condition. In the Joined Fields list,
“CustNo -> CustNo” appears.
Choose OK to commit your selections and exit the Field Link Designer.

11Set the Active properties of CustomersTable and OrdersTable to True to display data in the grids on the form.
12Compile and run the application.

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.


GOSTEI 0
POSTAR