procedure VariantToStream(const Data: OleVariant; Stream: TMemoryStream);
var
p: Pointer;
begin
p := VarArrayLock(Data);
try
Stream.Position := 0;
Stream.Write(p^, VarArrayHighBound(Data, 1) + 1);
finally
VarArrayUnlock(Data);
Stream.Position := 0;
end;
end;
function StreamToVariant(Stream: TStream): OleVariant;
var
p: Pointer;
begin
Result := VarArrayCreate([0, Stream.Size - 1], varByte);
p := VarArrayLock(Result);
try
Stream.Position := 0;
Stream.Read(p^, Stream.Size);
finally
VarArrayUnlock(Result);
Stream.Position := 0;
end;
end;