我需要从Stream读取并将缓冲区重新加入OleVariant
(VarArray)变量。
var
MemoryStream : TMemoryStream;
Data : OleVariant;
begin
MemoryStream:=TMemoryStream.Create;
try
FuncFill(MemoryStream); //Filling the stream
MemoryStream.Seek(0,0);
MemoryStream.Read(Data, MemoryStream.Size);//this line lock tha app, i need allocate the memory for the OleVariant variable?
finally
MemoryStream.Free;
end;
end;
问题是我如何将TMemoryStream
中的readed值分配给olevariant
变量?
我正在使用delphi 5.
答案 0 :(得分:6)
您可以使用VarArrayLock
函数获取指向OleVariant数据的指针,然后读取此指针。
使用VarArray
个varByte
元素检查此代码。
var
MemoryStream : TMemoryStream;
Data : OleVariant;
DataPtr : Pointer;
begin
MemoryStream:=TMemoryStream.Create;
try
FuncFill(MemoryStream); //Filling the stream
MemoryStream.Seek(0,0);
Data :=VarArrayCreate([0, MemoryStream.Size - 1], varByte);
DataPtr :=VarArrayLock(Data);
try
MemoryStream.ReadBuffer(DataPtr^,MemoryStream.Size); //Get the pointer to the variant variable.
finally
VarArrayUnlock(Data); //when you are done , you must call to VarArrayUnlock
end;
finally
MemoryStream.Free;
end;
end;