Home > Back-end >  OleVariant and STREAM conversion problem
OleVariant and STREAM conversion problem

Time:10-08

The function tform1. StreamToVariant (Strm: TMemoryStream) : OleVariant;
Var
Data: PByteArray;
The begin
Result:=VarArrayCreate ([0, Strm. Size - 1], varByte);
Data:=VarArrayLock (Result);
Try
Strm. Position:=0;
Strm. ReadBuffer (Data ^ Strm. Size);
The finally
VarArrayUnlock (Result);
end;
end;

The function tform1. VariantToStream (OV: OleVariant) : TMemoryStream;
Var
Data: PByteArray;
Size: integer;
The begin
Result:=TMemoryStream. Create;
Try
Size:=VarArrayHighBound (OV, 1) - VarArrayLowBound (OV, 1) + 1;
Data:=VarArrayLock (OV);
Try
Result. The Position:=0;
Result. The WriteBuffer (Data ^, Size);
The finally
VarArrayUnlock (OV);
end;
Except,
Result. The Free;
Result:=nil;
end;
end;

Procedure TForm1. Button1Click (Sender: TObject);
Var
Lszstream: TMemoryStream;
LszV: Variant;

The begin
Lszstream:=TMemoryStream. Create;
LszV:=vararrayof ([' 0 ']);
Lszstream:=VariantToStream (LSZV);
LSZV:=StreamToVariant (lszstream);
Edit1. Text:=LSZV [0];
Freeandnil (lszstream);

end;
Edit1. Text='8' what is going on

CodePudding user response:

Which help me have a look at the follows
  • Related