Ver Mensaje Individual
  #4  
Antiguo 21-06-2013
sleep25000 sleep25000 is offline
Miembro
NULL
 
Registrado: jun 2011
Posts: 29
Reputación: 0
sleep25000 Va por buen camino
Error en TObjectList

Gracias por tu respueta, lo he probado y me sigue dando el error, incluso he borrado todos los registros de marcas, me muevo por los registros maestros y cierro el form, y todo bien, pero si vuelvo a entrar en el form me salta un error:

Al cambiar el id, realizo las siguientes operaciones:
Código Delphi [-]
procedure TfmHorses.edIDChange(Sender: TObject);
var
  DirImage, TypeBrand: String;
  Left, Top, ID: Integer;
  Img: TImage;

begin
  inherited;
  BindingExpressions(Sender);

  // Archivo
  DirImage := dsHorseImages.DataSet.FieldByName('imageName').AsString;
  Image.Picture := NIL;
  // Obtenemos ficheros y rutas
  if RemoveWriteSpace(DirImage) <> '' then
  begin
    DirImage := iniPathImagesHorses + DirImage;

    // Si existe el fichero, cargamos la foto
    if fileExists(DirImage) then
      Image.Picture.LoadFromFile(DirImage);
  end;

  // Cargamos Marcas
  Load_Brands;
end;

Aquí cargo las marcas:
Código Delphi [-]
procedure TfmHorses.Load_Brands;
var
  AName, TypeBrand:String;
  NUM, ID, ALeft, ATop, I, Index:Integer;

begin

if BrandsLst.Count > 1 then
    BrandsLst.Clear;

  // Creamos archivo configuracion
  with dsHorseBrands.DataSet do
  begin
    if NOT(IsEmpty) then
    begin
      NUM := RecordCount;
        while NOT(Eof) do
        begin
          ID        := FieldByName('id').Value;
          AName     := FieldByName('name').Value;
          ALeft     := FieldByName('x').Value;
          ATop      := FieldByName('y').Value;
          TypeBrand := iniPathImages + IMAGES_BRANDS + FieldByName('type').Value;

          // Cargar marcas
          BrandsLst.Add(CreateBrand(AName, pnlReview, ALeft, ATop, TypeBrand, ID));

        // Siguiente Registro
        Next;
      end;
    end;
  end;

y al cerrar el form, hago lo siguiente desde el form que hereda:
Código Delphi [-]
//==============================================================================
// PROCEDIMIENTO FORM CLOSE
//==============================================================================
procedure TfmAncestor.FormClose(Sender: TObject; var Action: TCloseAction);
var
  I: Integer;
  C: TComponent;
  //DB: TClientDataSet;

begin

  Action := TCloseAction.caFree;

  // Comprobamos todos los componentes del formularios, en busca
  // de un TDataSource, y cerramos la tabla
  for I := 0 to ComponentCount - 1 do
  begin
    C := Components[i];
   
    // Cerramos dataset y establecemos la consulta inicial
    if (C is TDataSource) and (Assigned(TDataSource(C).DataSet)) then
    begin
      TDataSource(C).DataSet.Close;

      if TDataSource(C).Name = 'dsAllRows' then
        with TDataSource(C).DataSet as TClientDataSet do
          CommandText := SQL;
    end;
  end;
end;

Acabo de realizar una pruebas, he eliminado la siguiente sentencia del procedimiento Load_Brands, y de esta forma no me da ningún error:
Código Delphi [-]
if BrandsLst.Count > 1 then
    BrandsLst.Clear;
Responder Con Cita