Interchange of Variant and Stream

xiaoxiao2021-03-06  42

In COM, DCOM, COM often uses Variant, and more of the file operations in Delphi, more of STREAM, sometimes, require proper interchange!

Variant -> stream

VAR OV: Olevariant; MS: TSTREAM; P: POINTER; Begin Ov: = Dmmmain.comConnection.AppServer.TimeZone; MS: = TmemoryStream.create; ms.position: = 0; p: = varitelock (ov); ms.write (p ^, VararrayHighBound (OV, 1)); // Will this sentence? VaRRAYUNLOCK (OV);

Ms.Position: = 0; ... ms.free; end;

Stream -> Variant

Function TTCANTEENSVR.GET_TIMEZONE: OLEVARIANT; VAR ASTREAM: TSTREAM; MyBuffer: Pointer; Begin Try Astream: = TFileStream.create

FMOPENREAD;

Result: = VararrayCreate ([0, ASTREAM.SIZE - 1], Varbyte;

MyBuffer: = Vararraylock (Result);

Astream.readbuffer (MyBuffer ^, ASTREAM.SIZE);

Vararrayunlock (Result);

Finally

ASTREAM.FREE;

END;

转载请注明原文地址:https://www.9cbs.com/read-86887.html

New Post(0)