//---------------------------讀數據到olevariant
//pfileName:帶路徑的文件名
function Getobj(pfileName:string): OleVariant;
var fs:TFileStream;
begin
fs := TFileStream.Create(pfileName,fmOpenRead);
try
result := VarArrayCreate([0,fs.size-1],varbyte);
fs.position := 0;
fs.readbuffer(varArrayLock(result)^, fs.size);
finally
fs.free;
varArrayunlock(result);
end;
end;
//---------------------------從 olevariant 寫到新文件
function writeFileFromOle(pfileName:string;pOleVariant:OleVariant):integer;
var fs:TFileStream;
begin
result:=0;
fs := TFileStream.Create(pfileName,fmCreate);
try
try
fs.WriteBuffer(varArrayLock(pOleVariant)^, VarArrayHighBound(pOleVariant,1)+1);
except
result:=-1;
end;
finally
fs.free;
varArrayunlock(pOleVariant);
end;
end;
------------------------------ 函數說明:
//取得數組A的第Dim維的長度
function VarArrayHighBound(const A: Variant; Dim: Integer): Integer;
//創建數組
function VarArrayCreate(const Bounds: array of Integer; VarType: Integer): Variant;