whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1548)

Database (90)
Files (137)
Forms (107)
Graphic (116)
IDE (21)
Indy (5)
Internet / LAN (131)
IntraWeb (0)
Math (76)
Misc (127)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (268)
VCL (243)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

17 Visitors Online


 
...convert variant to Stream and then back?
Autor: ari
Homepage: http://borland.mblogger.cn/aiirii
[ Print tip ]  

Tip Rating (22):  
     


// Variant --> Stream

var 
  
ov: OleVariant;
  ms: TStream; 
  p: Pointer;
begin
  
ov := dmMain.ComConnection.AppServer.TimeZone;
  ms := TMemoryStream.Create;
  ms.Position := 0;
  p := VarArrayLock(ov);
  ms.Write(p ^, VarArrayHighBound(ov, 1));
 //is it the best way to get the Variant's length?
  
VarArrayUnlock(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;

  //--------------------------------------------------------------------
  //notice: I have asked this question on BDN, and David Lewis told me
  //        to use the function VarArrayLock.


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners