variant 为长二进制型(即:adodataset2.fieldbyname('finger').asvariant)
怎样将variant 转换成 array of varbyte 型数组 紧急,紧急,紧急

解决方案 »

  1.   

    type
      PByteArr = ^TByteArr;
      TByteArr = array [0..MaxInt] of Byte;function VarToByteArr(Value: Variant; var Buffer: Pointer): Integer;
    var
      P: Pointer;
      Len: Integer;
    begin
      P := VarArrayLock(Value);
      try
        Result := VarArrayHightBound(Value, 1);
        if Result = 0 then
          raise Exception.Create('Value不是数组变量');
        GetMem(Buffer, Result);    
        Move(P^, Buffer^, Result);
      finally
        VarArrayUnLock(Value);
      end;
    end;var
      Count: Integer;
      Buffer: Pointer;
      Value: array of Byte;
    begin
      Count := VarToByte(FieldByName('finger').AsVariant, Buffer);
      SetLength(Value, Count);
      Move(Buffer^, Value, Count);
      ....
      FreeMem(Buffer);//记得Free...
    end;
      

  2.   

    ok
    不过,我想问你怎样将olevariant型数据写入数据库(ole对象型)字段中