Discussion:
Nested master/detail -- all stuck in the detail
(too old to reply)
Frank Burleigh
2008-05-16 04:44:16 UTC
Permalink
I thought I'd freshen up an *old* BDE application that's been using our
old Sybase database. I've moved the data it uses to our Oracle instance
and thought I'd also ditch BDE in favor the DBX and client data sets.
I'm working in RAD 2007 (C++, mainly). I've accepted warnings against
the evils of master/detail done with TSimpleDatasets so thought I'd
spend a couple hours trying the nested approach so often suggested.

It's been a very long two hours. ;-)

There are two tables, A and B. B is detail. I've created:

For table A:
- aSDS_A select * from a
- aDSP_A whose datasource is aSDS_A
- aCDS_A whose provider is aDSP_A
- aDS_A whose dataset is aDSP_A

For table B:

- aSDS_B select * from B where db_obj=:db_obj (created param, input,
string, gave it a value in the designer), with datasource aDS_A.
- aCDS_B can't set DataSetField
- aDS_B with dataset aCDS_B

I believe the two CDSs are the trouble: the one for A doesn't
automagically create a TDataSetField for the data that should come from
aSDS_B. And unless there's some magical inferance from aSDS_B's
datasource being set to aDS_A, I don't quite understand why it would.

Because aCDS_A has no TDatasetField, it can't enter the picture.

I did find one paper:
http://conferences.codegear.com/article/32229#MasterDetail

but can't duplicate the behavior of the fields editer shown in figure
12, where the TDataSetField has been created by the designer.

So I'm stuck, and would appreciate some help forward.

Thanks very much.
Eduardo
2008-05-26 11:21:12 UTC
Permalink
Hi Frank.

I think you problably solved this problem...
I see myself with the exact same question.

What you need is an "extra" step don't mentioned...

1. Set the sql for the Master table.
2. Set the sql for the Detail table, with something like:

'SELECT * FROM wtDetails WHERE IDMaster = :IDMaster'

IDMaster is the key field on the Master table and a foreign key on Details table. The name of the parameter must match exactly the name of the key field on the master table.

3. Link the two table with a TDataSource.
4. Active the Master table (TSQLDataSet problably) and next the Details table
5. Double click on both. Will appear a window. Right click on it and click on "Add All Fields..." menu.
6. Put a TProviderDataSet linked to the Master table component.
7. Put a TClientDataSet component and set the Provider Name property to the Provider component previously put on form.
8. Double click on the TClientDataSet and do like on the TSQLDataSet components.
Vouala! The TDataField for the Details TSQLDataSet was created.
9. Put another TClientDataSet and set the DataSetField value to the one that will be listed now.

Now, the Nested Master Detail will work perfecly. You can put two TDataSource (one for each TClientDataSet) and Two DBGrids, setting their DataSource property to the DataSource linked to Master and Detail tables.

Active both the TClientDataSet and you will see the data on both DBGrid.

F9 on it and you can navigate on the Master DBGrid and the Details DBGrid will response on the very same instant.

This is really simple, but Took me over almost a day to find that litle "doble click add fields" TRICk to make it work...

Obviusly, because I don't have much experience with these type of arrangement, Someone told me what I was missing [;)]

These is really easy to do, but is not much "flexible". Because if you need to change the SQL on a "havey way", nothing will work anymore. For these cases is better do all that runtime.

I'm still studying this...

Bye!
Post by Frank Burleigh
I thought I'd freshen up an *old* BDE application that's been using our
old Sybase database. I've moved the data it uses to our Oracle instance
and thought I'd also ditch BDE in favor the DBX and client data sets.
I'm working in RAD 2007 (C++, mainly). I've accepted warnings against
the evils of master/detail done with TSimpleDatasets so thought I'd
spend a couple hours trying the nested approach so often suggested.
It's been a very long two hours. ;-)
- aSDS_A select * from a
- aDSP_A whose datasource is aSDS_A
- aCDS_A whose provider is aDSP_A
- aDS_A whose dataset is aDSP_A
- aSDS_B select * from B where db_obj=:db_obj (created param, input,
string, gave it a value in the designer), with datasource aDS_A.
- aCDS_B can't set DataSetField
- aDS_B with dataset aCDS_B
I believe the two CDSs are the trouble: the one for A doesn't
automagically create a TDataSetField for the data that should come from
aSDS_B. And unless there's some magical inferance from aSDS_B's
datasource being set to aDS_A, I don't quite understand why it would.
Because aCDS_A has no TDatasetField, it can't enter the picture.
http://conferences.codegear.com/article/32229#MasterDetail
but can't duplicate the behavior of the fields editer shown in figure
12, where the TDataSetField has been created by the designer.
So I'm stuck, and would appreciate some help forward.
Thanks very much.
Loading...