PDA

Ver la Versión Completa : Ayuda para traducir código delphi a c++ builder


mordaz
07-05-2014, 10:51:50
Que tal,

Alguien me puede ayudar a entender este codigo para traducirlo, principalmente hace 2 funciones convertir una variable Variant a un archivo y de un archivo a la variable de nuevo.

Este es el codigo de guardado:


procedure TForm1.SaveTemplate();
var
outFile : File of byte;
vrnt: Variant;
vtByteBuf : PByteArray;
aryLow: integer;
aryHigh : integer;
loopIndex : integer;
iTemplate : DPFPShrXLib_TLB.IDPFPTemplateDisp;
begin

try
if SaveDialog.Execute then
begin
iTemplate := DPFPEnrollment.Template as DPFPShrXLib_TLB.IDPFPTemplateDisp;
vrnt:=iTemplate.Serialize; //raw data is now stored in this variant

//Now that you have the variant, try to get raw byte array
//We are assuming here that you cannot save a variant directly to database field
//That you need a byte array before saving the data to the database.
aryLow:=VarArrayLowBound(vrnt,1);
aryHigh:=varArrayHighBound(vrnt,1);
aryHigh:=aryHigh-aryLow;

vtByteBuf:=VarArrayLock(vrnt); //lock down the array
AssignFile(outFile,saveDialog.FileName);
Rewrite(outFile);
for loopIndex := 0 to aryHigh do
begin
//fpData[loopIndex]:=vtByteBuf[loopIndex];
//bt:=fpData[loopIndex];
Write(outFile,vtByteBuf[loopIndex]); //Save directly to file here
end;
VarArrayUnlock(vrnt);
end;
except
on E: Exception do showmessage('Trouble saving data');
end;
CloseFile(outFile);


end;


Y este el codigo de recuperacion:

procedure TForm1.LoadTemplate;
var inFile : File of Byte;
vrnt: Variant;
vtByteBuf : PByteArray ;
loopIndex : integer;
length : integer;
bt : byte;
begin
if OpenDialog.Execute() then
begin
if OpenDialog.FileName <>'' then
begin

AssignFile(inFile,OpenDialog.FileName);
Reset(infile);

length:=FileSize(inFile);
vrnt := VarArrayCreate([0,length],varByte); //Allocate the array required to store the fpdata in your variant
vtByteBuf:=VarArrayLock(vrnt);
loopIndex:=0;
while not Eof(inFile) do
begin
Read(inFile,bt);
vtByteBuf[loopIndex]:=bt;
loopIndex:=loopIndex+1;
end;

VarArrayUnlock(vrnt);
CloseFile(inFile);

TemplateFromFile.Deserialize(vrnt);

end;
end;
end;


Espero que me puedan ayudar a entender el codigo para traducirlo. Gracias.