Master/details problems when inserting
Posted: Tue 14 Feb 2006 16:23
Hi,
We have just migrated our system from Delphi 4 to Delphi 7 changing all TTable components to TOraTable.
Suppose that I have the fields MyKey and MyDesc into MasterTable and the fields MyKey, MyDetailKey and MyDetailDesc into DetailTable.
First I insert into MasterTable and after I insert into DetailTable, when I execute MasterTable.Post, detailTable.Refresh happen and all detailtable data loses;
One example will be more clean:
DataSource: DataSet = MasterTable
MasterTable: CachedUpdates = True; KeyFields = MyKey
DataSourceDetail: Dataset = DetailTable;
DetailTable: CachedUpdates = True; MasterSource = DataSource; MasterFields = MyKey; DetailFields = MyKey
MasterTable.Insert;
MasterTableMyKey.Value := 1;
MasterTableMyDesc.Value := 'Bla bla bla';
DetailTable.Insert
DetailTableMyKey := 1;
DetailTableMyDetailKey := 1;
DetailTableMyDetailDesc := 'a';
DetailTable.Post;
DetailTable.Insert
DetailTableMyKey := 1;
DetailTableMyDetailKey := 2;
DetailTableMyDetailDesc := 'b';
DetailTable.Post;
MasterTable.Post; //at this moment happen the refresh into DetailTable - Oh god, I lost everything that I wrote
What am I doing Wrong ????
We have just migrated our system from Delphi 4 to Delphi 7 changing all TTable components to TOraTable.
Suppose that I have the fields MyKey and MyDesc into MasterTable and the fields MyKey, MyDetailKey and MyDetailDesc into DetailTable.
First I insert into MasterTable and after I insert into DetailTable, when I execute MasterTable.Post, detailTable.Refresh happen and all detailtable data loses;
One example will be more clean:
DataSource: DataSet = MasterTable
MasterTable: CachedUpdates = True; KeyFields = MyKey
DataSourceDetail: Dataset = DetailTable;
DetailTable: CachedUpdates = True; MasterSource = DataSource; MasterFields = MyKey; DetailFields = MyKey
MasterTable.Insert;
MasterTableMyKey.Value := 1;
MasterTableMyDesc.Value := 'Bla bla bla';
DetailTable.Insert
DetailTableMyKey := 1;
DetailTableMyDetailKey := 1;
DetailTableMyDetailDesc := 'a';
DetailTable.Post;
DetailTable.Insert
DetailTableMyKey := 1;
DetailTableMyDetailKey := 2;
DetailTableMyDetailDesc := 'b';
DetailTable.Post;
MasterTable.Post; //at this moment happen the refresh into DetailTable - Oh god, I lost everything that I wrote
What am I doing Wrong ????