Ir para conteúdo
Fórum Script Brasil
  • 0

Loop Infinito :(


hencker

Pergunta

Estou tentando transferir uns dados de um banco antigo para um novo banco da seguinte forma:

procedure TfrmPrincipal.BBMigrarClick(Sender: TObject);
begin
DMMigrator.TAntiga.First;
while not DMMigrator.TAntiga.Eof do begin
        DMMigrator.TNova.Append;
        DMMigrator.TNovaPROTOCOLONRO.Value              := DMMigrator.TAntigaProtocoloNro.Value;
        DMMigrator.TNovaPROTOCOLOLIVRONRO.Value         := DMMigrator.TAntigaProtocoloLivroNro.Value;
        DMMigrator.TNovaPROTOCOLOFOLHANRO.Value         := DMMigrator.TAntigaProtocoloFolhaNro.Value;
        DMMigrator.TNovaPROTOCOLODATA.Value             := DMMigrator.TAntigaProtocoloData.Value;
        DMMigrator.TNovaPROTESTOTIPO.Value              := DMMigrator.TAntigaProtestoTipo.Value;
        DMMigrator.TNovaTITULONATUREZA.Value            := DMMigrator.TAntigaTituloNatureza.Value;
        DMMigrator.TNovaTITULONATUREZAABR.Value         := DMMigrator.TAntigaTituloNaturezaAbr.Value;
        DMMigrator.TNovaTITULONRO.Value                 := DMMigrator.TAntigaTituloNro.Value;
        DMMigrator.TNovaTITULOVECTO.Value               := DMMigrator.TAntigaTituloVecto.Value;
        DMMigrator.TNovaTITULOEMISSAO.Value             := DMMigrator.TAntigaTituloEmissao.Value;
        DMMigrator.TNovaTITULOVALOR.Value               := DMMigrator.TAntigaTituloValor.Value;
        DMMigrator.TNovaPORTADORCNPJCPF.Value           := DMMigrator.TAntigaPortadorCnpjCpf.Value;
        DMMigrator.TNovaPORTADORNOME.Value              := DMMigrator.TAntigaPortadorNome.Value;
        DMMigrator.TNovaPORTADORENDERECO.Value          := DMMigrator.TAntigaPortadorEndereco.Value;
        DMMigrator.TNovaPORTADORCEP.Value               := DMMigrator.TAntigaPortadorCEP.Value;
        DMMigrator.TNovaPORTADORCIDADE.Value            := DMMigrator.TAntigaPortadorCidade.Value;
        DMMigrator.TNovaPORTADORUF.Value                := DMMigrator.TAntigaPortadorUF.Value;
        DMMigrator.TNovaCREDORCNPJCPF.Value             := DMMigrator.TAntigaCredorCnpjCpf.Value;
        DMMigrator.TNovaCREDORNOME.Value                := DMMigrator.TAntigaCredorNome.Value;
        DMMigrator.TNovaCREDORENDERECO.Value            := DMMigrator.TAntigaCredorEndereco.Value;
        DMMigrator.TNovaCREDORCEP.Value                 := DMMigrator.TAntigaCredorCEP.Value;
        DMMigrator.TNovaCREDORCIDADE.Value              := DMMigrator.TAntigaCredorCidade.Value;
        DMMigrator.TNovaCREDORUF.Value                  := DMMigrator.TAntigaCredorUF.Value;
        DMMigrator.TNovaOBSERVACOES.Value               := DMMigrator.TAntigaObservacoes.Value;
        DMMigrator.TNovaDEVEDORNOME.Value               := DMMigrator.TAntigaDevedorNome.Value;
        DMMigrator.TNovaDEVEDORENDERECO.Value           := DMMigrator.TAntigaDevedorEndereco.Value;
        DMMigrator.TNovaDEVEDORCIDADE.Value             := DMMigrator.TAntigaDevedorCidade.Value;
        DMMigrator.TNovaDEVEDORCEP.Value                := DMMigrator.TAntigaDevedorCep.Value;
        DMMigrator.TNovaDEVEDORUF.Value                 := DMMigrator.TAntigaDevedorUf.Value;
        DMMigrator.TNovaDEVEDORCNPJCPF.Value            := DMMigrator.TAntigaDevedorCnpjCpf.Value;
        DMMigrator.TNovaDEVEDORDOCID.Value              := DMMigrator.TAntigaDevedorDocId.Value;
        DMMigrator.TNovaDEPOSITOVALOR.Value             := DMMigrator.TAntigaDepositoValor.Value;
        DMMigrator.TNovaCUSTASTOTAL.Value               := DMMigrator.TAntigaCustasTotal.Value;
        DMMigrator.TNovaDISTRIBUICAONRO.Value           := DMMigrator.TAntigaDistribuicaoNro.Value;
        DMMigrator.TNovaDISTRIBUICAOORDEM.Value         := DMMigrator.TAntigaDistribuicaoOrdem.Value;
        DMMigrator.TNovaDISTRIBUICAOCARTORIO.Value      := DMMigrator.TAntigaDistribuicaoCartorio.Value;
        DMMigrator.TNovaOPERADOR.Value                  := DMMigrator.TAntigaOperador.Value;
        DMMigrator.TNovaDATAOP.Value                    := DMMigrator.TAntigaDataOp.Value;
        DMMigrator.TNovaCUSTASDISTRIBUICAO.Value        := DMMigrator.TAntigaCustasDistribuicao.Value;
        DMMigrator.TNovaCUSTASDILIGENCIA.Value          := DMMigrator.TAntigaCustasDiligencia.Value;
        DMMigrator.TNovaSITUACAOCODIGO.Value            := DMMigrator.TAntigaSituacaoCodigo.Value;
        DMMigrator.TNovaSITUACAO.Value                  := DMMigrator.TAntigaSituacao.Value;
        DMMigrator.TNovaDISTRIBUIDOR_ANOTACAO.Value     := DMMigrator.TAntigaDISTRIBUIDOR_ANOTACAO.Value;
        DMMigrator.TNova.ApplyUpdates;
end;
DMMigrator.TAntiga.Next;
end;

Porém ao invés de mandar todos os dados da tabela antiga para a nova ele copia infinitas vezes o primeiro registro do banco antigo...

Alguém sabe o que está errado, além do meu QI?

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0

hencker, passe o Next para dentro do begin...end do while

        DMMigrator.TNovaDISTRIBUIDOR_ANOTACAO.Value     := DMMigrator.TAntigaDISTRIBUIDOR_ANOTACAO.Value;
        DMMigrator.TNova.ApplyUpdates;
        DMMigrator.TAntiga.Next;    // ****  <=== AQUI
end;
end;
Uma dica: Se os campos da tabela de origem e de destino tem exatamente o memo nome, simplifique um pouco o código e minimize a digitação (tem campo pra caramba, ufa!!!) utilizando for com a propriedade Fields e with...do
procedure TfrmPrincipal.BBMigrarClick(Sender: TObject);
var
  Idx :Integer;
  Field :TField;
begin
  with DMMigrator do
  begin
    TAntiga.First;
    while not TAntiga.Eof do 
    begin
      TNova.Append;
      for Idx := 0 to TAntiga.Fields.Count -1 do
      begin
        Field := TNova.FindField(TAntiga.Fields[Idx].FieldName);
        if Assigned(Field) then
          Field.Assign(TAntiga.Fields[Idx]);
      end;
      TNova.ApplyUpdates;
      TAntiga.Next;
    end;
  end;
end;

[]s

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,7k
×
×
  • Criar Novo...