复制结构体或流到Variant里

set nocount on  在使用dbExperss时 在SQLSERVER的存储过程开头要写这一行,在尾select 之前写set nocount off

 

procedure VariantToStream(const Data: OleVariant; Stream: TStream);
var
  p: Pointer;
begin
  p := VarArrayLock(Data);
  try
    Stream.Write(p^, VarArrayHighBound(Data,1) + 1);  //assuming low bound = 0
  finally
    VarArrayUnlock(Data);
  end;
end;

function StreamToVariant(Stream: TStream): OleVariant;
var
  p: Pointer;
begin
  Result := VarArrayCreate([0, Stream.Size - 1], varByte);
  p := VarArrayLock(Result);
  try
    Stream.Position := 0;  //start from beginning of stream
    Stream.Read(p^, Stream.Size);
  finally
    VarArrayUnlock(Result);
  end;
end;

 

function RecToVariant(Rec:TMyRecArr):variant;
var
 p:PChar;
begin
   Result:=VarArrayCreate([0,SizeOf(Rec) - 1],VarByte);
   p:=VarArrayLock(Result);
   try
     Move(Rec[1], p^, SizeOf(Rec))
   finally
      VarArrayUnlock(Result);
   end;
end;

procedure VariantToRec(Value:variant): TMyRecArr;
var
 p:PChar;
 Size: Cardinal;
begin
 size:=VarArrayHighBound(Value,1);
 p:=VarArrayLock(Value);
 try
    Move(p^, Result[1], Size)
 finally
    VarArrayUnlock(Value);
 end;
end; 

你可能感兴趣的:(Stream,function,存储,sqlserver)