Subject Re: [IBO] Deactivate Detail Datasets (was: ...MasterSource)
Author Paul Vinkenoog
Hi Guido,

> > Very strange! Are you sure you have called DisableControls on the
> > MASTER dataset (or datasource) and not on the detail set(s)?
>
> No, on the detail set. I don't want the Master dataset to be
> disabled, but the detail sets. I have master-detail relationship
> between customers and contacts. Every customer have one ore more
> contacts. Normally when I scroll in the customers, the contacts are
> updated. But sometimes I want to deactivate the
> master-detail-relationship between them for some time. What I do
> now, is to close the contacts and after some time open them again,
> but I don't like this way.

OK, I see what you need: the master has to remain active and
scrollable from the user's point of view. That wasn't clear to me
yesterday (or maybe I was just too sleepy to understand ;-)).

DisableControls freezes detail set updates but also user-visible
controls, so you can't use that here on the master.
DisablesInterface freezes only the user-visible stuff, but not the
detail set updates, so that's even worse.

Using any of these two on a detail set doesn't help either: the detail
set will still be updated and the SQL will go across the wire, only
the user won't see it in the controls.

It would be nice if there was something like "DisableDetailUpdates" to
be called on the master source; a function that would just block
detail set notifications, but left the controls active. But IBO
doesn't provide that (afaict).

Open and Close works but I wouldn't be happy with that either.

Another option is:

- to freeze detail updates: DetailSet.MasterSource := nil;
- to re-enable them : DetailSet.MasterSource := MyMasterSource;

This works, and works fast.


But there's another solution that I think is "cleaner":

- Drop an extra IB_DataSource on your form or data module and set
its Dataset property to the master set (the Customers dataset).
Let's call this new datasource CustMasterSource for now.

- Leave the datasource of all your controls untouched, but set the
MasterSource (not the DataSource!) of the detail set (the Contacts
dataset) to CustMasterSource.

- Now if you want to disable updating of the detail set, call
CustMasterSource.DisableControls; this prevents the Contact set
from being updated when the master scrolls. No SQL will go across
the wire.
But the controls of the master set will still be active, because
they are linked through the other, "older" datasource.

An extra advantage is that if you later add new detail sets, you can
set their MasterSource to CustMasterSource too; one call to
CustMasterSource.DisableControls will prevent them all from updating.

By the way, the detail sets won't be really disabled. You can still
scroll through them; they just won't be updated when the master
scrolls -- until you call CustMasterSource.EnableControls

To disable the detail sets too, you'd have to make an additional call
<DetailSet>.DisableControls for each detail set. But that's normally
not necessary, unless you expect the user to do something stupid with
a detail set while the master-detail link is frozen.


Greetings,
Paul Vinkenoog