function StreamToVariant(stream:TStream):variant;
procedure VariantToStream(AVariant:variant;
stream:TStream);
function StreamToVariant(stream:TStream):variant;
var
p
Char;
begin
stream.Seek(0,0);
Result:=VarArrayCreate([0,stream.Size - 1],VarByte);
try
p:=VarArrayLock(Result);
try
stream.ReadBuffer(p^,stream.Size);
finally
VarArrayUnlock(Result);
end;
except
Result:=Unassigned;
end;
end;
// Get contents of a variant and put it in a stream.
procedure VariantToStream(AVariant:variant;
stream:TStream);
var
p
Char;
sz:integer;
begin
// Check if variant contains data and is an array.
if VarIsEmpty(AVariant) or VarIsNull(AVariant) or (not VarIsArray(AVariant)) then
exit;
sz:=VarArrayHighBound(AVariant,1);
p:=VarArrayLock(AVariant);
try
stream.WriteBuffer(p^,sz+1);
finally
VarArrayUnlock(AVariant);
end;
end;