title: DELPHI - EOleException caused by grid with +1000 records
body: <p>I have the following problem:</p>
  
  <p>I'm programming in DELPHI XE2 and using TDBAdvGrid by <a href="http://www.tmssoftware.com/site/" rel="nofollow">TMS</a>. The grid gets filled from an SQL SERVER. The moment I want to load +1000 records at once I get the following error:</p>
  
  <p><strong>First chance exception at $75CCC42D. Exception class EOleException with message 'There has occurred an unknown error'.</strong></p>
  
  <p>When I click 'Break', the pointer stops in the following code:</p>
  
  <pre><code>function TDBAdvGrid.GetRecordCount: integer;
  
    function RowsInDataset: Integer;
    var
      cb: TBookMark;
      iseof, isbof: Boolean;
    begin
      Result := -1;
      if not CheckDataSet then
        Exit;
  
      FDataLink.DataSet.DisableControls;
  
      iseof := FDataLink.DataSet.Eof;
      isbof := FDataLink.DataSet.Bof;
  
      if isbof and iseof then
      begin
        Result := 0;
    //FMaxRows := 0;
      end
      else
        with FDataLink.DataSet do
        begin
          cb := GetBookMark;
          First;
          if (csDesigning in ComponentState) then
            Result := MoveBy(100)
          else
            Result := MoveBy($7FFFFFFF) + 1; // &lt;= programs breaks here!
  
          GotoBookMark(cb);
          FreeBookMark(cb);
  
      //FMaxRows := Result;
        end;
  
      if iseof then
        FDataLink.DataSet.Next;
  
      if isbof then
        FDataLink.DataSet.Prior;
  
      if FDataLink.DataSet.State = dsInsert then
        Result := Result + 1;
  
      FEmptyDataSet := Result = 0;
      FDataLink.DataSet.EnableControls;
    end;
  
  //var
  //  OldRecNo: integer;
  begin
    Result := 0;
    if Assigned(FDataLink) then
      if Assigned(FDataLink.DataSet) then
        if FDataLink.DataSet.Active then
        begin
          FDoNotUpdateMe := true;
  
          if Assigned(FOnGetRecordCount) then
          begin
            FDataLink.DataSet.DisableControls;
            FOnGetRecordCount(self, Result);
            FEmptyDataSet := Result = 0;
            if (FloatingFooter.Visible) and PageMode and (FloatingFooter.FooterStyle = fsFixedLastRow) then
            begin
              if (Result = 0) then
                Inc(Result, 2)
              else
                Inc(Result);
            end;
            FDataLink.DataSet.EnableControls;
          end
          else
          begin
            Result := RowsInDataSet;
            if (FloatingFooter.Visible) and PageMode and (FloatingFooter.FooterStyle = fsFixedLastRow) then
            begin
              if (Result = 0) then
                Inc(Result, 2)
              else
                Inc(Result);
            end;
          end;
     { OldRecNo:= FDataLink.DataSet.RecNo;
      FDataLink.dataset.First;
      Result := FDataLink.dataset.MoveBy($FFFF);
      FDataLink.DataSet.RecNo:= OldRecNo; }
          FDoNotUpdateMe := false;
        end;
  end;
  
  //------------------------------------------------------------------------------
  </code></pre>
  
  <p>When I click 'Continue', I get in an infinite loop of this error. This error occurs only when I'm debug mode, when starting the exe outside Delphi and going to the form with the grid, there is no problem at all.
  It also only occurs on my PC, my colleagues don't have this problem.</p>
  
  <p>Updating TMS did not help.</p>
  
  <p>I have mailed to TMS, but they say it's a problem from Delphi itself and they can't help me. Are they right?</p>
  
  <p>At the moment I start the exe, load the grid, attach Delphi to the process and debug that piece of code I want. Not very handy but still better then nothing.</p>
  
  <p>What can I do?</p>
  
  <p><em>We are looking to upgrade to XE7 or even 10 Seattle in near future, but hopefully this could be fixed soon</em></p>
  
  <p><strong>EDIT - SOME EXTRA INFO</strong></p>
  
  <p>We recently made the step to DELPHI 10 SEATTLE, but the problem is still there. We also updated all TMS products.</p>
  
  <p>I searched and found the mails I sent back in the day to TMS (couldn't find them the first them).
  This is how the conversation went:</p>
  
  <ol>
  <li>First I sent an e-mail explaining what was going, including screenshots (very similar to this SO-question)</li>
  <li>I received an e-mail where they asked what dataset I'm using and if I could use the MoveBy instruction on the Dataset itself.</li>
  <li>I tried what they asked and yes, I get the same error if I do <code>adoquery.moveby($FFFFFFF)</code></li>
  <li>They said it was unclear why I get that error and it was the first time someone reported this. This is where they said it's a fault in the dataset itself and they can't help it.</li>
  </ol>
  
  <p>I have really no clue how to fix this...and I still don't understand why this only happens while debugging AND recordcount > 1000. Could it be something with paging?</p>
  
  <p>@ kobik: </p>
  
  <pre><code>procedure TfrmGrondstoffen.MainDBGridGetRecordCount(Sender: TObject;
    var Count: Integer);
  begin
       ShowMessage(inttostr(MainDBGrid.DataSource.DataSet.RecordCount)); // gives the correct number
       ShowMessage(inttostr(qryGrondstoffen.RecordCount));  //gives the correct number
       ShowMessage(inttostr(Count)); // gives 0 all the time
  end;  
  </code></pre>
  
  <p>Also a bit weird I received 12 messageboxes instead of 3</p>