Error in procedure TDataAbstractService.PackSimpleDeltas

delphi

(Christen Blom Dahl) #1

I think there is an error in the procedure TDataAbstractService.PackSimpleDeltas. The lines

lRows.OldValues.Add( ConvertToSimple(lDelta[i].OldValues[k], lDelta.LoggedFieldTypes[k]));
lRows.NewValues.Add( ConvertToSimple(lDelta[i].NewValues[k], lDelta.LoggedFieldTypes[k]));

that use the index variable i to access the lDelta changes data should use the index variable j. As a result in some cases the procedure does not work properly.
The correct code for this procedure should be:

function TDataAbstractService.PackSimpleDeltas(
  const aDelta: IDeltaArray): SimpleDeltaArray;
var
  i,j,k: Integer;
  lDelta:  IDADelta;
  lSimpleDelta : SimpleDelta;
  lRows: SimpleDeltaChange;
  s: string;
begin
  Result := SimpleDeltaArray.Create;
  for i:=  0  to  Length(aDelta)-1  do  begin
    lDelta := aDelta[i];
    lSimpleDelta := Result.Add;
    lSimpleDelta.TableName := ROStringToUTF8String(lDelta.LogicalName);
    for j :=  0  to lDelta.LoggedFieldCount-1  do
      lSimpleDelta.Fields.Add(ROStringToUTF8String(lDelta.LoggedFieldNames[j]));

    for  j :=  0  to  lDelta.Count-1  do  begin
      lRows := lSimpleDelta.Rows.Add;
      if (lDelta[j].Status = csResolved)  then
        lRows.Error := ''
      else begin
        s :=lDelta[j].Message;
        if s = '' then s := 'Error';
        lRows.Error := ROStringToUTF8String(s);
      end;

      for k:=  0  to lDelta.LoggedFieldCount-1  do  begin
        lRows.OldValues.Add( ConvertToSimple(lDelta[j].OldValues[k], lDelta.LoggedFieldTypes[k]));
        lRows.NewValues.Add( ConvertToSimple(lDelta[j].NewValues[k], lDelta.LoggedFieldTypes[k]));
      end;
    end;
  end;
end;

(RemObjects) #2

Thanks, logged as bugs://81757


(RemObjects) #3

bugs://81757 got closed with status fixed.