Icon View Incident Report

Serious Serious
Reported By: Fernando Dias
Reported On: 9/7/2008
For: Version 2.01 Build 4
# 2775 SetRange Can Result In Incorrect Ranges of Rows with Unique Indexes

I found an issue with Ranges, and you can see what's going on as follows:

1. Click "Set Range" button - This will set a range on the table that shouldn't be empty, but it is, as you can see in the grid.

2. Click "Clear Range" - As you can see now, there are records in the table that should be in the range you first set.

I can't explain why, but it seems that sometimes the problem doesn't happen as I described. If you can't see the issue happening as I just said, please click "Copy Records".

After a while you will get an exception. You must now cancel the table "MovL" using the navigator and repeat steps 1 and 2. You will certainly see now what I first described.

The code associated with the "Copy Records" button is the "original code" that was being executed when I first detected the issue.

function AlDireita(n: Integer): String;
var s: string;
begin
  s:=IntToStr(n);
  while Length(s)<12 do s:=' '+s;
  Result:=s;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Diario,
  NumLanc,
  Linha: Integer;
begin
   dbGrid2.DataSource:=nil;
   dbNavigator2.DataSource:=nil;
   try
     Mov.IndexFieldNames:='AnoDoc;TipoDoc;SerieDoc;NumDoc;AbrFecho';
     Rec.First;
     While not Rec.Eof do
     begin
       if Mov.FindKey([2008, 'NRE', RecSerieRecibo.Value, AlDireita(RecNumRecibo.Value), 'F']) then
       begin
         Diario :=MovDiario.Value;
         NumLanc:=MovNumLanc.Value;
         MovL.SetRange([Diario, NumLanc, 0],[Diario, NumLanc, MaxInt]);
         MovL.First;
         while not MovL.eof do
         begin
           MovL.Delete;
           MovL.First;
         end;
         MovL.CancelRange;

         Linha:=1;
         RecL.First;
         while not RecL.eof do
         begin
           MovL.Append;
           MovLDiario.value  :=98;
           MovLNumLanc.Value :=NumLanc;
           MovLLinha.Value:=Linha;
           MovLTipoLanc.Value:=RecLTipoLanc.Value;
           MovLAnoDoc.Value  :=RecLAnoDoc.Value;
           MovLTipoDoc.Value :=RecLTipoDoc.Value;
           MovLSerieDoc.Value:=RecLSerieDoc.Value;
           MovLNumDoc.Value  :=RecLNumDoc.Value;
           MovLDataDoc.Value :=RecLDataDoc.Value;
           MovLValor.Value   :=RecLValor.Value;
           Inc(Linha);
           MovL.Post;
           RecL.Next;
         end;
       end;
       Rec.Next;
     end;
   finally
      dbGrid2.DataSource:=DataSourceMovL;
      dbNavigator2.DataSource:=DataSourceMovL;
   end;
end;
//
//******* End of "Original Code" ***********

procedure TForm1.Button4Click(Sender: TObject);
begin
  Mov.IndexFieldNames:='Diario;NumLanc';
  Mov.FindKey([98, 84]);

  MovL.SetRange([MovDiario.Value,MovNumLanc.Value,0],
                [MovDiario.Value,MovNumLanc.Value,MaxInt]);

end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  MovL.CancelRange;
  MovL.FindKey([98, 84, 1]);
end;



Comments Comments
The problem was caused by the SetRange not handling the beginning of the range properly when first building the range. This was also the reason for the duplicate key exception - the initial loop to delete all of the rows in the range didn't work properly due to the first row being skipped over due to the same navigation problem on the beginning of the range.


Resolution Resolution
Fixed Problem on 9/10/2008 in version 2.01 build 5


Products Affected Products Affected
ElevateDB VCL Client-Server
ElevateDB VCL Client-Server with Source
ElevateDB VCL Standard
ElevateDB VCL Standard with Source
ElevateDB VCL Trial

Image