IBTable Master-Detail relationships.

IBTable Master-Detail relationships.

Post by Will » Fri, 11 Jun 2004 07:32:50

I'm putting together a little test app to help me figure some stuff out.
Something, that I thought would be simple, doesn't appear to be as simple as
I thought, or else I'm missing something.

Anyway, if I set up a Master/detail relationship at design time, then view
it in the running test app, it works the way I think it should. Cycle
through the master, and the detail changes as necessary. However, when I try
to set the properties, those that appear to be modified at design time by
the Object Inspector, at runtime, the M/D no longer works.

I have a form, with one grid per table. The topmost grid is the master
table, the remaining four are detail tables. At design time, I set the
Database and TableName properties of the master table, then associate a
TDatasource with it. Then, I take each of the remaining four TIBTable
components, setting their TableName, Database properties, and then the
MasterSource property to the TDataSource associated with the Master table.
Then, when I click the ellipsis on the MasterFields property, a small dialog
appears, from which I pick the two fields that join the tables, and click
OK. This then adds the MasterTable key to the MasterFields property, and
sets the IndexFieldNames to the Detail table's key. When I run the program
and scroll through the Master tables records, the remaining four grids
change their display as the Master changes.

Now, this is nice, but I have a choice of three potential Master tables. So,
what I want to do is to change the Master at runtime, which should only
require the changing of the Detail table's MasterFields property. When I do
that at runtime, and scroll through the Master table, the other 4 grids do
nothing. This obviously is not what I want.

Below is the code that changes the MasterFields property:

// set these to nil, so that no errors occur while changing property
tblAddress.MasterSource := nil;
tblEmail.MasterSource := nil;
tblPhone.MasterSource := nil;
tblEvent.MasterSource := nil;
// change the property to the key of the new table
tblAddress.MasterFields := 'EEMPLOYEEID';
tblEmail.MasterFields := 'EEMPLOYEEID';
tblPhone.MasterFields := 'EEMPLOYEEID';
tblEvent.MasterFields := 'EEMPLOYEEID';
// close the Master table, change the table, then reopen
tblEntity.TableName := 'EMPLOYEE';
// reassociate the details tables with the mastersource table
tblAddress.MasterSource := dsEntity;
tblEmail.MasterSource := dsEntity;
tblPhone.MasterSource := dsEntity;
tblEvent.MasterSource := dsEntity;

What am I missing?


IBTable Master-Detail relationships.

Post by Will » Fri, 11 Jun 2004 08:10:06

Got it.


IBTable Master-Detail relationships.

Post by Will » Sun, 20 Jun 2004 03:59:29

Thanks for the link. Interesting reading.