Duplicate call from onclick event in Delphi

Asked

Viewed 151 times

0

When running the onclick event (from the btn_ImportarNFe button) the program calls the same onclick event again from the method call Nfe.EnviarEvento(StrToInt(IDLote)); from the second code snippet (see full listing below). When running the same onclick event in debug mode this second call does not happen.

Code snippet from Procedure Importanfe:

    procedure Tfrm_LancamentosDespesas.btn_ImportarNFeClick(Sender: TObject);
var
  dlgImportarNFe       : TFrm_BuscarChave;
  Chave, CNPJ, idLote  : string;
  i                    : Integer;
  XMLtsl               : TStringList;
  XMLStream            : TStringStream;
begin
  dlgImportarNFe :=  TFrm_BuscarChave.Create(nil);
  XMLtsl    := TStringList.Create;
  XMLStream := TStringStream.Create;

  dlgImportarNFe.ShowModal;

  if dlgImportarNFe.ModalResult = mrCancel then
  begin
    Exit
  end
  else
  begin
    if dlgImportarNFe.chk_BuscarXML.Checked = False then
    begin
      Chave          := dlgImportarNFe.edt_Chave.Text;
      CNPJ           := dm.EmpresaControlada.CGC;
      idLote         := '1';

      dlgImportarNFe.free;

      dm_NFe.EventoConfirmacao(Chave, idLote, CNPJ);
      dm_NFe.DistribuicaoDFePorChaveNFe(31, CNPJ, Chave);
      op.FileName    := dm_NFe.nfe.Configuracoes.Arquivos.DownloadNFe.PathDownload + dm_NFe.nfe.WebServices.DistribuicaoDFe.ListaArqs[0];
    end;
...

Code snippet with Send method :

procedure Tdm_NFe.EventoConfirmacao(Chave, idLote, CNPJ: string);
var
  lMsg      : string;
  RetornoWS : string;
begin
  Chave  := Trim(OnlyNumber(Chave));
  idLote := Trim(OnlyNumber(idLote));
  CNPJ   := Trim(OnlyNumber(CNPJ));

  nfe.Configuracoes.WebServices.Ambiente      := dm_NFe.tipoAmbiente;
  nfe.Configuracoes.Certificados.NumeroSerie  := dm_logon.dat_EmpresaCTRLNUMSERIE_NFE.AsString;
  nfe.Configuracoes.WebServices.UF            := 'MG';
  DataModuleCreate(nil);

  Nfe.EventoNFe.Evento.Clear;
  with Nfe.EventoNFe.Evento.Add do
  begin
    InfEvento.cOrgao   := 91;
    infEvento.chNFe    := Chave;
    infEvento.CNPJ     := CNPJ;
    infEvento.dhEvento := now;
    infEvento.tpEvento := teManifDestConfirmacao;
  end;

  Nfe.EnviarEvento(StrToInt(IDLote));
...

Does anyone know what might be going on?

  • Matheus, can you put something to "trace" where exactly this is happening? Enter some parts of the code with "Try...catch" to see if you’re picking up any exceptions. Some messages displaying variable values with Showmessage can also help.

  • It has already been placed and since returned nothing has been removed.

  • According to you program calls the same onclick event again from the Nfe.Enviar method call(Strtoint(Idlote));... What’s inside the Nfe method.Submit Event?

  • Nfe.Enviar event(Strtoint(Idlote)); and where the proper checks are made to send the event to the government, specifically in this section Result := Webservices.EnvEvento.Execute; it happens the duplicity.

  • I was able to solve the problem, what was happening and that I was not cleaning object before using it. soon after opening dlgImportarNFe.Showmodal;, dm_NFe.nfe.Notasfiscais.Clear was inserted; to clear the object.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.