Master detail detail, cached updates, and insert/delete

I have a master-detail-detail relationship on a form, represented by

Master:
   fields

Detail:
   grid

Detail's detail:
  another grid

The detail is set by a param based on the key of the master, and the
detail's detail is a set of all records related (eventually) back to
the master. When moving between detail records, I apply a filter to the
detail's detail.

Now, my question is this:
How do I implement cached updates on this form, allowing for updates
and deletes before applying the changes?

The problem occurs because the order of the queries that need to be
applied is different in an insert from a delete.

If I pass TDatabase.ApplyUpdates(Master, Detail1, Detail2) on an
insert, this works fine. If I pass TDatabase.ApplyUpdates(Detail2,
Detail1, Master) on a delete, this also works fine. But, if there have
been some Detail1/Detail2 records deleted and some further
Details1/Details2 records added, I cannot apply the updates without
referential integrity going mental.

In the past, I have solved this problem by making sure there was only
ever a master-detail relationship on a form; but this time, it is not
going to make much sense to do this. I need to have a master-detail-
detail relationship represented on a single form.

Help greatly appreciated,

Cheers,
Raymond Barlow

Sent via Deja.com http://www.deja.com/
Before you buy.