Fórum Criar uma dll e usa-la no delphi #614051

07/02/2021

0

Boa tarde

Tenho uma rotina em C# que lê o webservice dos correios e retornam o endereço de acordo com um cep informado. Eu preciso transformar isto em uma DLL e utiliza-la no delphi.
Eu sei que da pra fazer isto diretamente no delphi, inclusive já tenho esta rotina funcionando. só que isto é requisito de trabalho. Tem que funcionar desta forma.

Alguém pode me dar uma ajuda?

Antecipadamente muito obrigado pela atenção de vocês...
Amauri Alves

Amauri Alves

Responder

Post mais votado

08/02/2021

Boa tarde

Tenho uma rotina em C# que lê o webservice dos correios e retornam o endereço de acordo com um cep informado. Eu preciso transformar isto em uma DLL e utiliza-la no delphi.
Eu sei que da pra fazer isto diretamente no delphi, inclusive já tenho esta rotina funcionando. só que isto é requisito de trabalho. Tem que funcionar desta forma.

Alguém pode me dar uma ajuda?

Antecipadamente muito obrigado pela atenção de vocês...


Boa tarde,
Tenho um DLL parecida, porem o meu webservice esta em um form de consulta...
mas vou passar o codigo da dll removi alguns outros codigos mas o da consulta ta ai:

[code=delphi]
library SoapsGenDll;

{ 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
System.SysUtils,
System.StrUtils,
System.Classes,
System.Variants,
System.RegularExpressions,
System.UITypes,
System.DateUtils,
Vcl.Dialogs,
forms,
IdSMTP,
IdSSLOpenSSL,
IdMessage,
IdText,
IdAttachmentFile,
IdExplicitTLSClientServerBase,
idHTTP,
idSNTP,
idAuthentication,
IdGlobal,
Soap.SOAPHTTPClient,
REST.client,
REST.Types,
REST.Authenticator.OAuth,
REST.Json,
uCorreiosAtendeCliente in 'uCorreiosAtendeCliente.pas',
uClassesObj in 'uClassesObj.pas';

function WideStringToString(pWdStr: WideString): string;
begin
result := Copy(pWdStr, 1, MaxInt);
end;

{ R *.res }
/// <summary> Apenas verifica se um determinado valor (variant) é nulo ou não </summary>
/// <param name="xValue"> Variant, verifica se o valor É Nulo. Obs 'inteiros', 'smallint', 'single', 'double', 'currency' são considerados nulos se '-1'</param>
/// <returns> Retorna verdadeiro se NULO, e falso se NÂO NULO </returns>
function E_Nulo(xValue: Variant): Boolean;
var
sTmp : String;
iDia, iMes, iAno: Word;
begin
{ Pré-Definição do Retorno }
result := true;

case VarType(xValue) of
VarEmpty:
begin
result := true;
end;

varNull:
begin
result := true;
end;

varSmallInt:
begin
result := (xValue = -1);
end;

varInteger:
begin
result := (xValue = -1);
end;

varSingle:
begin
result := (xValue = -1);
end;

varDouble:
begin
result := (xValue = -1);
end;

varCurrency:
begin
result := (xValue = -1);
end;

varDate:
begin
result := (xValue = Null);
if not result then
begin
DecodeDate(xValue, iAno, iMes, iDia);
if ((iDia = 30) and (iMes = 12) and (iAno = 1899)) then
begin
result := true;
end;
end;

if not result then
begin
sTmp := DateToStr(xValue);
sTmp := ReplaceStr(sTmp, '/', '');
sTmp := ReplaceStr(sTmp, '-', '');
sTmp := ReplaceStr(sTmp, '.', '');

result := E_Nulo(sTmp);
end;
end;

varString, varUString:
begin
result := (Length(ReplaceStr(xValue, ' ', '')) = 0);
end;

varOleStr:
begin
result := (xValue = Null);
end;

varDispatch:
begin
result := (xValue = Null);
end;

varByte:
begin
result := (xValue = Null);
end

else
begin
if xValue = Null then
begin
result := true;
Exit;
end;
end;
end;
end;

/// <summary> Apenas verifica se um determinado valor (variant) NÂO È NULO </summary>
/// <param name="xValue"> Variant, verifica se o valor NÂO É NULO. Obs 'inteiros', 'smallint', 'single', 'double', 'currency' são considerados nulos se '-1'</param>
/// <returns> Retorna TRUE se NÂO NULO, e FALSE se NULO </returns>
function Nao_Nulo(xValue: Variant): Boolean;
begin
result := not E_Nulo(xValue);
end;

/// <summary> Método que efetua a consulta do CEP no serviço dos correios.</summary>
/// <param name="pCEP"> Entrada: Código do CEP de consulta </param>
/// <param name="pInfoComplentar"> Saida: Retorna dados complementares do endereço </param>
/// <param name="pLogradouro"> Saida: Tipo e Nome do Logradouro </param>
/// <param name="pBairro"> Saida: Nome do Bairro, as vezes pode vir vázio, fazer a checagem na cidade</param>
/// <param name="pCidade"> Saida: Nome da cidade, as vezes pode vir junto o nome de um bairro </param>
/// <param name="pUF"> Saida: UF do endereço </param>
function ConsultaCEP(pCEP: WideString; //
out pInfoComplentar: WideString; //
out pLogradouro: WideString; //
out pBairro: WideString; //
out pCidade: WideString; //
out pUF: WideString): WideString; stdcall; export; //
var
CorreiosConsultaCEP : AtendeCliente;
CorreiosRetornoEnderecoERP: enderecoERP;
CepStr : String;
MeusServicos : buscaServicosAdicionaisAtivosResponse;
begin
try
try
CepStr := ReplaceText(ReplaceText(pCEP, '-', ''), '.', '');

if Length(trim(CepStr)) <> 8 then
raise Exception.Create('CEP inválido! Digite apenas os 8 números do CEP');

CorreiosConsultaCEP := GetAtendeCliente(true, '', nil);
pInfoComplentar := 'Null';
pLogradouro := 'Null';
pBairro := 'Null';
pCidade := 'Null';
pUF := 'Null';

try
CorreiosRetornoEnderecoERP := CorreiosConsultaCEP.ConsultaCEP(CepStr);

if CorreiosRetornoEnderecoERP <> nil then
with CorreiosRetornoEnderecoERP do
begin
if Nao_Nulo(complemento2) then
pInfoComplentar := complemento2;

if Na

Marcelo Oliveira

Marcelo Oliveira
Responder

Gostei + 1

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

Aceitar