Delphi - Problemas de conversion

 
Vista:

Problemas de conversion

Publicado por Luis Hurtado (6 intervenciones) el 01/08/2001 18:03:33


Necesito enviar un registro usando SendBuf, asi que debo convertir el registro en un arraglo de caracteres. Lo hice con el siguiente procedimiento
type

DynArrayChar = array of char;
DynArrayCharPtr = ^DynArrayChar;
CharPtr = DynArrayCharPtr;

Person = Record
Name : CharPtr;
Age : integer;
NbName : integer;
end;
PersonPtr = ^Person;
BytePtr = ^byte;

procedure RecordToCharPtr(P : Pointer; var cad : CharPtr);
var
aux : PersonPtr;
i,j,n : integer;
DynAux1,DynAux2 : CharPtr;
pcharAux1 : PChar;
begin
aux := PersonPtr(P);
n := sizeof(Person) + aux^.NbName;

try
new(DynAux1);
SetLength(DynAux1^,n);
except
//rollos para reservar memoria
end;

pcharAux1 := PChar(aux);
j := 0;

n := sizeof(Person);
for i:=0 to n-1 do
begin
DynAux1^[j] := char(pcharAux1^);
pcharAux1 := pcharAux1 + 1;
j := j + 1;
end;

DynAux2^ := aux^.Name^;
for i:=0 to aux^.NbName-1 do
begin
DynAux1^[j] := DynAux2^[i];
j := j + 1;
end;

cad := DynAux1;
end;


Pero cuando voy a lconvertir el arrglo de caracteres en Registro

procedure CharPtrToRecord(cad : CharPtr; var P : Pointer);
var
i,n : integer;
DynAux : CharPtr;
PerPtrAux : PersonPtr;
begin
n := sizeof(Person);

try
new(DynAux);
SetLength(DynAux^,n);
except
//rollos con la memoria
end;

for i:=0 to n - 1 do
DynAux^[i] := cad^[i];

PerPtrAux := PersonPtr(DynAux);

for i:=0 to PerPtrAux^.NbName - 1 do
PerPtrAux^.Name^[i] := cad^[i + n];

P := PerPtrAux;
end;

El campo NbName tiene un valor erroneo, llevo cuatro dias en este plan y todavia no he podido hacer las conversiones, si me puedes ayudar te agradezco mucho.

Saludo y gracias.

Hurtado
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder