uses
OleDB, ADOInt;
...
type
TAffectRecords = (arCurrent, arFiltered, arAll, arAllChapters);
THackADODataSet = class(TCustomADODataSet);
...
procedure DoRecordsetDelete(DataSet: TCustomADODataSet; AffectRecords: TAffectRecords);
const
AffectRecordsValues: array[TAffectRecords] of TOleEnum =
(adAffectCurrent, adAffectGroup, adAffectAll, adAffectAllChapters);
begin
with DataSet do
try
THackADODataSet(DataSet).CheckActive;
UpdateCursorPos;
CursorPosChanged;
with Recordset do
try
if AffectRecords in [arAll, arAllChapters] then begin
MoveFirst;
while (RecordCount > 0) do begin
Delete(adAffectCurrent);
DataSet.Resync([]);
end;
end
else
Delete(AffectRecordsValues[AffectRecords]);
{ When CacheSize > 1, Recordset allows fetching of deleted records.
Calling MovePrevious seems to work around it }
if (CacheSize > 1) and (PRecInfo(ActiveBuffer).RecordNumber <> 1) then begin
MovePrevious;
MoveNext;
end;
// MoveNext;
except
on E: Exception do
begin
CancelUpdate;
DatabaseError(E.Message);
end;
end;
finally
Resync([]);
end;
end;