After switching to asynchronous operations for TADOStoredProc
, one issue periodically arises in TDBGrid
handlers, for example in OnDrawColumnCell
:
I check the data set for Empty
, find out that it has data, and in the next line it turns out that there is no data anymore and I get an exception.
I cannot use the OnFetchComplete
handler because it is unreliable for purpose of signalling that asynchronous operations are completed.
procedure TPurchasesFrame.dgGridDrawColumnCell(Sender: TObject; const Rect:
TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
DataSet: TDataSet;
f: TField;
begin
try
DataSet := dgGrid.DataSource.DataSet;
// .....
if (State = []) and (not DataSet.IsEmpty()) then begin // Is not empty
f := DataSet.FieldByName('GroupNr');
if (f <> nil) and (not Odd(f.AsInteger)) then begin // Occasionally an Exception. Not necessarily occurs at this location. May also occur at other similar.
dgGrid.Canvas.Brush.Color := _alternateColor;
end;
end;
// .....
dgGrid.DefaultDrawColumnCell(Rect, DataCol, TTntColumn(Column), State);
except
on ex: Exception do _addError(ex);
end;
end;
Is it possible to lock the data set state or have a snapshot of it while OnDrawColumnCell
handler is executing?