Hi,
I have a three level entity structure. TEntityA contains a List of TEntityB (1st level detail). TEntityB contains two Lists of TEntityC1 and TEntityC2 (2nd detail level).
The issue I am having is that I need to perform an operation that uses the first level entities(TEntityB) but theses entities need to be sequentially ordered (I display data in a DevExpress TcxGrid, which takes care of the "on display sorting"). For this, I apply the following procedure:
procedure TSD_WellSchematic.SortCasingList(ADetailList: TList<TEntityB>);
var
Comparer: IComparer<TEntityB>;
begin
// Sort entities so we can iterate and draw in correct sequence
Comparer := TDelegatedComparer<TEntityB>.Create(
function(const Entity1, Entity2: TEntityB): Integer
begin
case CompareValue(Entity1.DoubleValue, Entity2.DoubleValue) of
LessThanValue:
result := -1;
GreaterThanValue:
result := 1;
else
result := 0;
end;
end);
ADetailList.Sort(Comparer);
end;
var
Comparer: IComparer<TEntityB>;
begin
// Sort entities so we can iterate and draw in correct sequence
Comparer := TDelegatedComparer<TEntityB>.Create(
function(const Entity1, Entity2: TEntityB): Integer
begin
case CompareValue(Entity1.DoubleValue, Entity2.DoubleValue) of
LessThanValue:
result := -1;
GreaterThanValue:
result := 1;
else
result := 0;
end;
end);
ADetailList.Sort(Comparer);
end;
The first thing I notice is that after the operation (sorting), particular records (that were moved by sorting) display values of other records when beginning to edit a cell. This however, is simply sorted by refreshing the TAureliusDataSet.
The greater problem lies in the fact that when I attempt to delete a record in one of the second level details (TEntityC1 or TEntityC2 list), I first get an AV followed by a "Bookmark not found". Looking at the Call Stack, it fails in Aurelius.Bind.BaseDataset.TBaseAureliusDataset.InternalSetToRecord and Aurelius.Bind.BaseDataset.TBaseAureliusDataset.InternalGotoBookmark.
Obviously a pointer is "lost" but what doesn't make sense to me, is that when I sort the list of TEntityB objects, the TEntityC1List and TEntityC2List properties shouldn't change and still point to the correct TList's which in turn still point to the correct entity objects.
Clearly there is a problem, so where is my thinking wrong? What am I missing?
Of course I'd also like to know if there's a way to work around this. Refreshing datasets does not seem to have an effect for the 2nd level lists; only for the first level (that is actually sorted).
Looking forward to your reply. This is an interesting problem as I am working on programs that typically need to iterate records sorted by depth or date(time)….
Rgds, Mark