文件和Variant之间的转换

时间:2010-02-01 13:19:07  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:Variant; var AStream: TFileStream; MyBuffer: Pointer; begin   AStream:=TFileStream.create(FileName,fmOpenRead);   try     aStream.Seek(0, soFromBeginning);     Result:=VarArraycreate([0, AStream.size-1], VarByte);     MyBuffer...
  正文:文件转Variant,Variant转文件:


function FileToVariant(FileName: String): OleVariant;
var
AStream: TFileStream;
MyBuffer: Pointer;
begin
  AStream:=TFileStream.create(FileName,fmOpenRead);
  try
    aStream.Seek(0, soFromBeginning);
    Result:=VarArraycreate([0, AStream.size-1], VarByte);
    MyBuffer:=VarArrayLock(Result);
    AStream.ReadBuffer(MyBuffer^, AStream.Size);
    VarArrayUnlock(Result);
    finally
      AStream.Free;
    end;
  end;
  
  
  procedure VariantToFile(FileName: String; var AVariant: OleVariant);
  var
  AStream: TFileStream;
  MyBuffer: Pointer;
  Size: Integer;
  begin
    AStream:=TFileStream.create(FileName,fmCreate);
    try
      aStream.Seek(0, soFromBeginning);
      Size:=VarArrayHighBound(AVariant,1)+VarArrayLowBound(AVariant,1)+1;
      MyBuffer:=VarArrayLock(AVariant);
      AStream.WriteBuffer(MyBuffer^, Size);
      VarArrayUnlock(AVariant);
      finally
        AStream.Free;
      end;
    end;

文件和Variant之间的转换》由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/12726.html


关键字:

关于《文件和Variant之间的转换》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td