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.
– Rodrigo Tognin
It has already been placed and since returned nothing has been removed.
– Matheus Lopes
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?
– Matheus Ribeiro
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.
– Matheus Lopes
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.
– Matheus Lopes