Tariq
2006-03-20 12:41:23 UTC
I have a situation where I convert (using the function shown below) any
binary file to an OleVariant and then send it to a DCOM Server which
converts it back to a FileStream and saves it to a disk.
On the client computer if I load a file into a TFileStream then every
thing works fine. However in some siutations I have a file loaded in a
TMemoryStream. If I convert the content of TMemoryStream in to an
OleVariable and send it to COM server, it saves an EMPTY file on the
disk. It seems as if the binary content in the TFileStream is not
handled the same way as it is handled in TMemoryStream.
I want some suggestion as to
(1) How can I safely copy the content of TMemoryStream to a TFileStream
or
(2) Convert the Content of TMemoryStream to an OleVariant.
Here is the function that I use to convert a FileStream to OleVariant:
function StreamToOleVariant(Stream: TStream; Count: integer):
OleVariant;
var pBuf: Pointer;
begin
Result :=VarArrayCreate([0, Count-1], varByte);
pBuf := VarArrayLock(Result);
Stream.Read(TByteArray(pBuf^), Length(TByteArray(Result)));
VarArrayUnlock(Result);
end;
binary file to an OleVariant and then send it to a DCOM Server which
converts it back to a FileStream and saves it to a disk.
On the client computer if I load a file into a TFileStream then every
thing works fine. However in some siutations I have a file loaded in a
TMemoryStream. If I convert the content of TMemoryStream in to an
OleVariable and send it to COM server, it saves an EMPTY file on the
disk. It seems as if the binary content in the TFileStream is not
handled the same way as it is handled in TMemoryStream.
I want some suggestion as to
(1) How can I safely copy the content of TMemoryStream to a TFileStream
or
(2) Convert the Content of TMemoryStream to an OleVariant.
Here is the function that I use to convert a FileStream to OleVariant:
function StreamToOleVariant(Stream: TStream; Count: integer):
OleVariant;
var pBuf: Pointer;
begin
Result :=VarArrayCreate([0, Count-1], varByte);
pBuf := VarArrayLock(Result);
Stream.Read(TByteArray(pBuf^), Length(TByteArray(Result)));
VarArrayUnlock(Result);
end;