Buenas:
Soy programador en Java, Visual Basic, C++ y ahora por motivos de trabajo me veo obligado a pelearme con Delphi.
Y me encuentro con un problema, que no he sido capaz de solucionar pero que tengo la impresion que se debe a mi corto conocimiento del lenguaje.
Estoy haciendo una DLL que se pueda usar en un entorno Windows desde cualquier lenguaje de programacion, estoy haciendo pruebas con .Net y con VB6.
Y tengo dentro de mi DLL una Unit con el siguiente metodo:
Código Delphi
[-]
procedure getDocumentListResponseDoc(const docIndex : PLongInt;
var RdocIdentification : PLongInt;
var RsuperState : PChar;
var Rstate : PChar;
var Rformat : PChar;
var RsubmissionDate : PChar;
var RdocNumber : PChar;
var RdocFunction : PChar;
var RcompanyName : PChar;
var RidentityCount : PLongInt);
var
docSend : ddoc;
docReceived : odoc;
index : LongInt;
sDocIdent : LongInt;
sSState : String;
sState : String;
sFormat : String;
sSubmissionDate : String;
sDocNumber : String;
sDocFunction : String;
sCompanyName : String;
sIdentityCount : LongInt;
PdocIdentification:PLongInt;
PsuperState:PChar;
Pstate:PChar;
Pformat:PChar;
PsubmissionDate:PChar;
PdocNumber:PChar;
PdocFunction:PChar;
PcompanyName:PChar;
PidentityCount:PLongInt;
begin
index := LongInt(docIndex);
if (receivedDocumentList = nil)then
begin
if (sendDocumentList = nil) then
begin
strLastMessage := 'No data to recover';
intLastCode := NO_STORED_DATA;
end
else
begin
if ((index > -1) and (index < Length(sendDocumentList))) then
begin
docSend := sendDocumentList[index];
case docSend.state of
NEW:sSState:= 'NEW';
DOWNLOADED:sSState:= 'DOWNLOADED';
DECLINED:sSState:= 'DECLINED';
ACCEPTED:sSState:= 'ACCEPTED';
MODIFIED:sSState:= 'MODIFIED';
end;
case docSend.superState of
OPEN:sState := 'OPEN';
CLOSED:sState := 'CLOSED';
end;
sDocIdent := docSend.documentId;
sFormat := docSend.format;
sSubmissionDate := DateTimeToStr(docSend.submissionDate.AsDateTime);
sDocNumber := docSend.documentNumber;
sDocFunction := docSend.documentFunction;
sCompanyName := docSend.destination.companyName;
sIdentityCount := Length(docSend.destination.listIdentityID);
PdocIdentification:=PLongInt(sDocIdent);
PsuperState:=PChar(sSState);
Pstate:=PChar(sState);
Pformat:=PChar(sFormat);
PsubmissionDate:=PChar(sSubmissionDate);
PdocNumber:=PChar(sDocNumber);
PdocFunction:=PChar(sDocFunction);
PcompanyName:=PChar(sCompanyName);
PidentityCount:=PLongInt(sIdentityCount);
RdocIdentification := PdocIdentification;
RsuperState := PsuperState;
Rstate := Pstate;
Rformat := Pformat;
RsubmissionDate := PsubmissionDate;
RdocNumber := PdocNumber;
RdocFunction := PdocFunction;
RcompanyName := PcompanyName;
RidentityCount := PidentityCount;
strLastMessage := 'OK';
intLastCode := TRANSACTION_OK;
end
else
begin
strLastMessage := 'Index out of range';
intLastCode := NO_DOC_AT_INDEX;
end;
end;
end
else
begin
if ((index > -1) and (index < Length(receivedDocumentList))) then
begin
docReceived := receivedDocumentList[index];
case docReceived.state of
NEW:sSState:= 'NEW';
DOWNLOADED:sSState:= 'DOWNLOADED';
DECLINED:sSState:= 'DECLINED';
ACCEPTED:sSState:= 'ACCEPTED';
MODIFIED:sSState:= 'MODIFIED';
end;
case docReceived.superState of
OPEN:sState := 'OPEN';
CLOSED:sState := 'CLOSED';
end;
sDocIdent := docReceived.documentId;
sFormat := docReceived.format;
sSubmissionDate := DateTimeToStr(docReceived.submissionDate.AsDateTime);
sDocNumber := docReceived.documentNumber;
sDocFunction := docReceived.documentFunction;
sCompanyName := docReceived.origin.companyName;
sIdentityCount := Length(docReceived.origin.listIdentityID);
PdocIdentification:=PLongInt(sDocIdent);
PsuperState:=PChar(sSState);
Pstate:=PChar(sState);
Pformat:=PChar(sFormat);
PsubmissionDate:=PChar(sSubmissionDate);
PdocNumber:=PChar(sDocNumber);
PdocFunction:=PChar(sDocFunction);
PcompanyName:=PChar(sCompanyName);
PidentityCount:=PLongInt(sIdentityCount);
RdocIdentification := PdocIdentification;
RsuperState := PsuperState;
Rstate := Pstate;
Rformat := Pformat;
RsubmissionDate := PsubmissionDate;
RdocNumber := PdocNumber;
RdocFunction := PdocFunction;
RcompanyName := PcompanyName;
RidentityCount := PidentityCount;
strLastMessage := 'OK';
intLastCode := TRANSACTION_OK;
end
else
begin
strLastMessage := 'Index out of range';
intLastCode := NO_DOC_AT_INDEX;
end;
end;
end;
La idea de este metodo es que una llamada SOAP me devuelva los valores y yo los almacene en estos Punteros que le paso por parametro y los recupere desde la aplicacion cliente que usa esta DLL.
Pero me pasa algo muy curioso, en principio si depuro los valores dentro del codigo de la DLL estan bien pero al devolver los punteros estan con algunos caracteres extraños.
Y es mas, cuando los asigno por ejemplo a un campo de texto tipo TEdit de
la siguiente manera :
los valores de los otros punteros se van modificando mientras voy realizando las asignaciones y el valor que tenian cuando la funcion me devolvio se va modificando sin yo hacer nada mas que la asignacion que pongo arriba.
Ademas me aparecen los valores de unos en otros sin yo haberselos asignado.
Este es el metodo que uso para invocarlo :
Código Delphi
[-]
procedure TTestDllForm.TestGetDocListRespDocClick(Sender: TObject);
var
index : Plongint;
SdocIdentification : plongint;
SsuperState : Pchar;
Sstate : Pchar;
Sformat : Pchar;
SsubmissionDate : Pchar;
SdocNumber : Pchar;
SdocFunction : Pchar;
ScompanyName : Pchar;
SidentityCount : plongint;
begin
SdocIdentification := nil;
SsuperState := nil;
Sstate := nil;
Sformat := nil;
SsubmissionDate := nil;
SdocNumber := nil;
SdocFunction:= nil;
ScompanyName := nil;
SidentityCount := nil;
index := PLongInt(StrToInt(txtGetDocListRespDoc.text));
getDocumentListResponseDoc(index,
SdocIdentification,
SsuperState,
Sstate,
Sformat,
SsubmissionDate,
SdocNumber,
SdocFunction,
ScompanyName,
SidentityCount);
txtIdGetDocListRespDoc.Text := IntToStr(LongInt(SdocIdentification));
txtSSGetDocListRespDoc.Text := String(SsuperState);
txtSGetDocListRespDoc.Text := String(Sstate);
txtGetDocListRespDocFormat.Text := String(Sformat);
txtGetDocListRespDocDate.Text := String(Pchar(SsubmissionDate));
txtGetDocListRespDocNum.Text := String(Pchar(SdocNumber));
txtGetDocListRespDocFunc.Text := String(Pchar(SdocFunction));
txtGetDocListRespDocComp.Text := String(Pchar(ScompanyName));
txtGetDocListRespDocIdent.Text := IntToStr(LongInt(SidentityCount));
end;
Supongo que sera una chorrada fruto de mi desconocimiento pero no he sido capaz de arreglarlo. Cualquier ayuda sera bien recibida. Muchas gracias.