resync method
Implementation
void resync(TResyncMode mode) {
if (_isUniDirectional) return;
// Now look if the data on the current cursor of the underlying
// dataset is still available (original comment kept as-is)
if (getRecord(_buffers[0]!, TGetMode.gmCurrent, false) !=
TGetResult.grOK) {
// If that fails and rmExact is set, then raise an exception
if (mode.contains(TResyncModeItem.rmExact)) {
databaseError(SNoSuchRecord, this);
}
// else, try to fetch the next or prior record in the underlying
// dataset
else if (getRecord(_buffers[0]!, TGetMode.gmNext, true) !=
TGetResult.grOK &&
getRecord(_buffers[0]!, TGetMode.gmPrior, true) !=
TGetResult.grOK) {
// nothing found, invalidate buffer and bail out. (original comment kept as-is)
clearBuffers();
dataEvent(TDataEvent.deDataSetChange, 0);
return;
}
}
_currentRecord = 0;
_eof = false;
_bof = false;
// If we've arrived here, FBuffer[0] is the current record (original comment)
int count;
if (mode.contains(TResyncModeItem.rmCenter)) {
count = _recordCount ~/ 2;
} else {
count = _activeRecord;
}
var i = 0;
_recordCount = 1;
_activeRecord = 0;
// Fill the buffers before the active record (original comment kept as-is)
while (i < count && getPriorRecord()) {
i++;
}
_activeRecord = i;
// Fill the rest of the buffer
getNextRecords();
// If the buffer is not full yet, try to fetch some more prior
// records
if (_recordCount < _bufferCount) {
_activeRecord += getPriorRecords();
}
// That's all folks! (original comment kept as-is)
dataEvent(TDataEvent.deDataSetChange, 0);
}