OleVariant怎么转换为Tstream(100分)

  • 主题发起人 主题发起人 winterind
  • 开始时间 开始时间
W

winterind

Unregistered / Unconfirmed
GUEST, unregistred user!
OleVariant怎么转换为Tstream,请高手赐教
 
procedure VariantToStream(const Data: OleVariant; Stream: TStream);
var
p: Pointer;
begin
p := VarArrayLock(Data);
try
Stream.Write(p^, VarArrayHighBound(Data,1) + 1); //assuming low bound = 0
finally
VarArrayUnlock(Data);
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; //start from beginning of stream
Stream.Read(p^, Stream.Size);
finally
VarArrayUnlock(Result);
end;
end;
 
后退
顶部