- assigned_to: nobody --> daverowntree
I'm using a special TClientDataSet component based on
yours from the incremental fetching sample. With Delphi
7.1 I found a problem: I'm using a DBGrid to show data.
With a resolution of 1024x768 the DBGrid can display 30
or 31 records, depending on the horizontal scrollbar. So
I decided to use 30 as PacketRecords value. To refresh
data I close and open the ClientDataSet but this
generates a Key Violation error when DBGrid is showing
more than 30 records at once (31 - so the
ClientDataSet has to fetch 2 packets). The error is
raised when fetching the second packet.
Whe opening the ClientDataSet for the first time
everyting works ok.
I have fixed the problem and I want you to take a look
to the solution. This is the code: (my lines with //#PR)
function TDSClientDataSet.DoGetRecords(Count:
Integer;
out RecsOut: Integer; Options: Integer; const
CommandText: WideString;
Params: OleVariant): OleVariant;
var
OwnerData, v: OleVariant;
iRecordCount: integer; //#PR
begin
iRecordCount := 0; //#PR
if Assigned(DSCursor) then // #PR
Check(DSCursor.GetRecordCount(iRecordCount)); //#PR
if (not Active and (iRecordCount = 0)) or //#PR
(grReset in TGetRecordOptions(Byte(Options)))
then //#PR
// if not Active or (grReset in TGetRecordOptions(Byte
(Options))) then
ResetIncFetch;
DoBeforeGetRecords(OwnerData);
if ((not Active) and (Count > 0))
or (Active and not ProviderEOF) then
PutIncFetchVar(OwnerData, MakeIncFetchVar
(FIncFetchFields, FIncFetchValues));
Result := AppServer.AS_GetRecords(ProviderName,
Count, RecsOut, Options,
CommandText, Params, OwnerData);
UnPackParams(Params, Self.Params);
v := ExtractIncFetchVar(OwnerData);
if VarIsArray(v) then
begin
FIncFetchFields := v[1];
FIncFetchValues := v[2];
end;
DoAfterGetRecords(OwnerData);
end;
For the second packet (not the firt time you open the
ClientDataSet) the value of Active is False so
ResetIncFetch is called and the value of
FIncFetchValues is Unassigned when calling
PutIncFecthVar.
Thanks, Pablo Reyes
preyes@excite.com