GARANTIR DESCONTO

Fórum ACBrNFe - Consulta estado cliente #431534

26/12/2012

0

Boa tarde.

Estou com um problema na minha dll para a consulta se o cliente esta habilitado ou denegado.

A dll em si, funciona perfeitamente. Porem ela so executa uma vez! Quando eu tento realizar duas consultas uma atraz da outra na segunda vez ela trava e nao roda mais!

Alguem pode me ajudar?

library OsSit;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  Windows,
  Messages,
  SysUtils,
  Variants,
  Classes,
  Graphics,
  Dialogs,
  StdCtrls,
  SHDocVw,
  ACBrNFe,
  Controls,
  XMLIntf,
  XMLDoc,
  ACBrNFeUtil,
  Forms,
  ExtCtrls,
  Buttons,
  ComObj,
  pcnAuxiliar,
  pcnConversao,
  sharemem in 'C:\Users\lucas\Documents\backDelphi10\RAD Studio\7.0\source\Win32\rtl\sys\sharemem.pas';

var
  ACBrNFe1 : TACBrNFe;
  XMLDocument1 : TXMLDocument;
  memoResp, msg : String;
  pro : Boolean;

function consultarCadastro(UF, Documento : String) : String; stdcall;
var
  Node1, Node2 : IXMLNode;
begin
  Documento := Trim(NotaUtil.LimpaNumero(Documento));

  pro := True;
  If length(UF) <> 2 then
  begin
    ShowMessage('UF inválido!');
    pro := False;
  end;

  if ValidarCNPJ(Documento) = False then
  begin
    ShowMessage('CNPJ inválido!');
    pro := False;
  end;

  if pro = True then
  begin
    ACBrNFe1 := TACBrNFe.Create(ACBrNFe1);
    XMLDocument1 := TXMLDocument.Create(XMLDocument1);

    ACBrNFe1.Configuracoes.Geral.FormaEmissao := teContingencia;
    ACBrNFe1.Configuracoes.Geral.PathSalvar := 'C:\Program Files (x86)\Embarcadero\RAD Studio\7.0\bin\';
    ACBrNFe1.Configuracoes.WebServices.AjustaAguardaConsultaRet := True;
    ACBrNFe1.Configuracoes.WebServices.IntervaloTentativas := 1000;

    try
      {$IFNDEF ACBrNFeOpenSSL}
        ACBrNFe1.Configuracoes.Certificados.NumeroSerie := ACBrNFe1.Configuracoes.Certificados.SelecionarCertificado;
      {$ENDIF}

      ACBrNFe1.WebServices.ConsultaCadastro.UF   := UpperCase(UF);
      ACBrNFe1.WebServices.ConsultaCadastro.CNPJ := Documento;

      ACBrNFe1.WebServices.ConsultaCadastro.Executar;

      if ACBrNFe1.WebServices.ConsultaCadastro.xMotivo <> 'Rejeicao: CNPJ da consulta nao cadastrado como contribuinte na UF' then
      begin
        MemoResp := UTF8Encode(ACBrNFe1.WebServices.ConsultaCadastro.RetWS);
        XMLDocument1.Active := False;
        XMLDocument1.XML.Clear;
        XMLDocument1.XML.Text := memoResp;
        try
          XMLDocument1.Active := True;
        Except
          ShowMessage('Não foi possível verificar o estado. Espaços em branco no XML!');
          Exit;
        end;

        Node1 := Nil;
        Node1 := XMLDocument1.DocumentElement.ChildNodes.FindNode('infCons');

        if Node1.ChildNodes.FindNode('infCad') <> Nil then
        begin
          Node2 := Nil;
          Node2 := Node1.ChildNodes.FindNode('infCad');

          if Node2.ChildNodes.FindNode('xNome') <> Nil then
          begin
            msg := 'CLIENTE: '+Node2.ChildNodes['xNome'].Text;
          end;
        end;

        if Node1.ChildNodes.FindNode('infCad') <> Nil then
        begin
          Node2 := Nil;
          Node2 := Node1.ChildNodes.FindNode('infCad');

          if Node2.ChildNodes.FindNode('cSit') <> Nil then
          begin
            if (Node2.ChildNodes['cSit'].Text) = '1' then
            begin
              Result := 'Habilitado';
              msg := msg+chr(13)+'ENCONTRA-SE HABILITADO.';
              ShowMessage(msg);
            end
            else
            begin
              Result := 'Denegado';
              msg := msg+chr(13)+'ENCONTRA-SE DENEGADO.';
              ShowMessage(msg);
            end;
          end;
        end;
      end
      else
        ShowMessage(ACBrNFe1.WebServices.ConsultaCadastro.xMotivo);
    finally
      ACBrNFe1 := nil;
      XMLDocument1 := Nil;
    end;
  end;
end;

exports
  consultarCadastro;

{$R *.res}

begin
end.



Agradeço desde ja!
Att: Vinicius Sanchez
Vinicius Snachez

Vinicius Snachez

Responder

Posts

26/12/2012

Vinicius Snachez

Galera... eu descobri o erro!

Fiz o seguinte: No finally eu apaguei o que tinha e fiz isso:

    finally
      {$IFDEF ACBrNFeOpenSSL}
        ACBrNFe1 := nil;
        XMLDocument1 := Nil;
        ACBrNFe1.Free;
        XMLDocument1.Free;
      {$ENDIF}
    end;


Agora eu posso executar a dll o tanto de vezes necessário que da certo!
Agradeço pela ajuda!
Flws
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar