diff --git a/Source/Base/Utiles/uDBSelectionListUtils.pas b/Source/Base/Utiles/uDBSelectionListUtils.pas index af2a9cf5..391f1d74 100644 --- a/Source/Base/Utiles/uDBSelectionListUtils.pas +++ b/Source/Base/Utiles/uDBSelectionListUtils.pas @@ -106,7 +106,7 @@ function TSelectedRecords.CurrentRow: integer; begin if not FDataTable.Active then raise EDatabaseError.Create(sDataSetClosed); - Result := FDataTable.FieldByName('ID').AsInteger; + Result := FDataTable.GetRowRecIDValue; end; function TSelectedRecords.GetCurrentRowSelected: Boolean; @@ -158,7 +158,8 @@ function TSelectedRecords.LocateItem(const Index: Integer) : Boolean; begin if not FDataTable.Active then raise EDatabaseError.Create(sDataSetClosed); - Result := FDataTable.Locate('ID', Items[Index], []); + Result := FDataTable.Locate(FDataTable.RecIDField.FieldName, Items[Index], []); + end; diff --git a/Source/Base/Utiles/uDataTableUtils.pas b/Source/Base/Utiles/uDataTableUtils.pas index 983e944d..294300e0 100644 --- a/Source/Base/Utiles/uDataTableUtils.pas +++ b/Source/Base/Utiles/uDataTableUtils.pas @@ -60,8 +60,8 @@ procedure CopyDataTableDA5(ASource : TDADataTable; ATarget: TDADataTable; var DABin: Binary; DADataStreamer : TDABin2DataStreamer; - AFilter : String; AFiltered : Boolean; + AFilter : String; AObj : ISeleccionable; i : Integer; begin @@ -73,6 +73,12 @@ begin if not Supports(ASource, ISeleccionable, aObj) then raise Exception.Create('El origen de datos no soporta la interfaz ISeleccionable (CopyDataTable)'); + { Si la tabla está abierta, la cerramos antes de aplicar los filtros + porque por cada cambio en el filtro se hacen llamadas internas de TDADataTable. } + if ASource.Active then + ASource.Close; + + // Si la tabla origen viene con un filtro, lo guardamos para luego restablecerlo. if ASource.Filtered then begin AFiltered := True; @@ -81,19 +87,18 @@ begin end; ASource.Filter := ''; -// if ASource.Active then -// ASource.Close; //Si no hay elemento seleccionados filtramos para que ATarget se quede vacia if (AObj.SelectedRecords.Count = 0) then - ASource.Filter := ASource.Filter + '(ID = ' + IntToStr(ID_NULO) + ')' + ASource.Filter := ASource.Filter + '(' + ASource.RecIDField.FieldName + ' = ' + IntToStr(ID_NULO) + ')' + //En caso contrario filtramos por los elementos seleccionados else for i := 0 to AObj.SelectedRecords.Count - 1 do begin if (i > 0) then ASource.Filter := ASource.Filter + ' or '; - ASource.Filter := ASource.Filter + '(ID = ' + IntToStr(AObj.SelectedRecords.Items[i]) + ')'; + ASource.Filter := ASource.Filter + '(' + ASource.RecIDField.FieldName + ' = ' + IntToStr(AObj.SelectedRecords.Items[i]) + ')'; end; ASource.Filtered := True; end; @@ -108,8 +113,9 @@ begin ATarget.LogicalName := ASource.LogicalName; // We need to specify new dataset LogicalName ATarget.RemoteFetchEnabled := False; // "Desconectamos" la tabla destino del servidor -// if not ASource.Active then -// ASource.Open; + if not ASource.Active then + ASource.Open; + ASource.First; DADataStreamer.WriteDataset(DABin, ASource, [woRows, woSchema], -1); @@ -459,7 +465,7 @@ begin else begin ATarget.First; - if not ATarget.Locate('ID', ASource.FieldByName('ID').AsVariant, []) then + if not ATarget.Locate(ATarget.RecIDField.FieldName, ASource.GetRowRecIDValue, []) then DuplicarRegistro(ASource, ATarget, WithPKKey, WithFKKey); end;