VariantRecordVariantStream transcript variant

//TARec--->Variant
function RecordToVariant(value:TParamRecord):OleVariant;
var P:Pointer;
begin
Result:=VarArrayCreate([0,sizeof(TParamRecord)],varByte);
P:=VarArrayLock(Result);
Move(value,P^,SizeOf(TParamRecord));
VarArrayUnlock(Result);
end;

//OleVariant---->TARec
function VariantToRecord(value:OleVariant):TParamRecord;
var P:Pointer;
begin
P:=VarArrayLock(value);
Move(P^,Result,SizeOf(TParamRecord));
VarArrayUnlock(value);
end;

好像不好使。先留着。

以下不知道好使否,也先留着。

http://dev.csdn.net/develop/article/53/53251.shtm

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));//這句可否改進?
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;

Record --> Stream

var r,r2:TStockInfo;p:Pointer;iRecSize,StringSize:Integer;
pc:PChar;
s:string;v:Variant;
ms:TMemoryStream;
begin
// TStockInfo=record
//SecurityID:string[12];
//CompanyID:string[12];
//InternalID:string[12];
// end;
// 赋值Record
r.SecurityID:='123';
r.CompanyID:='456';
r.InternalID:='789';
iRecSize:=SizeOf(TStockInfo);
StringSize:=SizeOf(string);
GetMem(p,iRecSize);
GetMem(pc,StringSize);
ms:=TMemoryStream.Create;
// Move测试
Move(r,p^,iRecSize); //赋值到指针
Move(p^,r2,iRecSize); // 赋值到验证Record
ms.WriteBuffer(p,iRecSize);
ms.SaveToFile(AppPath+'test.txt');
//ShowMessage(r2.SecurityID+','+r2.CompanyID+','+r2.InternalID);
// 移动指针
// 这里需要转换指针类型,string->PCharInteger->PInteger Double->PDouble等等
//Inc(PChar(p),StringSize); //跳过SecurityID
// 赋值CompanyID
// Move(P^,pc,StringSize);
// Move(P^,s,StringSize);
VariantRecordVariantStream transcript variant
// ShowMessage(StrPas(pc));
// Dec(PChar(p),StringSize); // 回来
FreeMem(p);// 并且释放
ms.Free;
end;

  

爱华网本文地址 » http://www.413yy.cn/a/25101017/352461.html

更多阅读

高尔夫旅行版用车感受 高尔夫用车感受

这段时间开着湖北尚腾提供的大众进口高尔夫Variant旅行版,1.4T双增压配7速双离合,百公里加速8.4秒,售价28.98万元。谈谈感受。旅行车对于欧洲人是最司空见惯的,但对于中国消费者来说,却是既熟悉又陌生的车型。旅行车市场在国内的消费心

vb6.0 判断数组为空 vb6.0定义数组

方法一:Error方法就是采用通用的错误捕获功能On Error Goto 行号 '遇到错误,转到行号处处理On Error Resume Next '忽略错误,继续执行On Error Goto 0 '强制取消错误捕获功能Function IsNotEmpty(ByVal sArray As Variant) As Boolean

声明:《VariantRecordVariantStream transcript variant》为网友眼角耀眼的光分享!如侵犯到您的合法权益请联系我们删除