title: RecordIndex out of range - DevExpress
body: <p>I am having issues with a DevExpress VCL grid, throwing out a "RecordIndex out of range" error, despite not directly calling any record functions of the grid in that scenario.</p>
  
  <p>What I am doing is fairly simple: once the record is changed(AfterScroll), a method is called. Inside this method, I call another method which assigns the data source and data fied name according to a field in the new record.</p>
  
  <p>The code is pretty simple and goes like this:</p>
  
  <pre><code>procedure TValidatedOrders.UpdateDispenseNotes;
  var Dataset : TDataSet;
      GroupTypeFieldName : String;
      DataSource : TDataSource;
      DataFieldName : String;
      GroupType : Integer;
  
      procedure SetSpecsDataSource;
      begin
           DataSource := DMValidatedDispense.DSDispenseGroupSpecs;
           DataFieldName := 'GLAZING_INSTRUCTIONS';
      end;
  
      procedure SetCLsDataSource;
      begin
           DataSource := DMValidatedDispense.DSDispenseGroupCLs;
           DataFieldName := 'WEAR_INSTRUCTIONS';
      end;
  begin
       // Step 1: Get the group type
       If GetTopPage = cTopPageOrders Then
          Dataset := DMValidatedDispense.CDSLabOrders
       Else
          Dataset := DMValidatedDispense.CDSLabDispenses;
  
       GroupType := Dataset.FieldByName( 'GROUP_TYPE' ).AsInteger;
       // Step 2: Assign the MemoDispenseNotes data binding appropriately
       If GetTopPage = cTopPageOrders Then
       Begin
           case GroupType of
           cOrderGroupSpecs, cOrderGroupFrame,
           cOrderGroupLens, cOrderGroupGlazing: SetSpecsDataSource;
           cOrderGroupCLs: SetCLsDataSource;
           else SetSpecsDataSource;
           end;
       End
       Else
       Begin
            case GroupType of
            cDispenseGroupSpecs: SetSpecsDataSource;
            cDispenseGroupCLs: SetCLsDataSource;
            else SetSpecsDataSource;
            end;
       End;
       MemoDispenseNotes.DataBinding.DataSource := DataSource;
       MemoDispenseNotes.DataBinding.DataField := DataFieldName;     
  end;
  </code></pre>
  
  <p>The original code where the above method is called is just too long to report here, anyway it contains stuff like panels show/hide, checks of the type .FieldByName( 'GROUP_TYPE' ).AsInteger = SomeValue and so on: there's no locate, no FindKey or anything like that.</p>
  
  <p>As I said, there's no record selection directly involved(not sure here what's going on inside the DevExpress grid though...) and I don't see why I'd be getting such error.</p>
  
  <p>Anybody has got a brilliant idea of what could be going on?</p>
  
  <p>Thank you very much!</p>