title: Delphi COM Passing ByteArray as OleVariant
body: <p>I'm interfacing fingerprint reader via COM and i need help converting VB.NET and C++ Code to Delphi.</p>
  
  <p>The API takes olevariant as parameter:</p>
  
  <pre><code>Function FingerPrint.GetData(var ImageData : OleVariant) : WordBool;
  </code></pre>
  
  <p>VB.NET example provided:</p>
  
  <pre><code>Dim imgData() as Byte
  ReDim imgData(fingerPrint.ImageSize) as Byte
  
  If fingerPrint.GetData(imgData) = True Then  
     'Success
  End If
  </code></pre>
  
  <p>C++ example provided:</p>
  
  <pre><code>BYTE* dataBuff = new BYTE[fingerPrint.ImageSize];
  VARIANT imgData;
  
  imgData.vt = VT_BYREF|VT_UI1;
  imgData.pbVal = dataBuff;
  
  if(fingerPrint.getData(imgData) == TRUE) {
    //Success
  }
  </code></pre>
  
  <p>Here's my Delphi Code:</p>
  
  <pre><code>procedure GetImgData();
  var varBuffer : OleVariant;
      imgBuff : PByteArray;
  begin
       GetMem(imgBuff, fingerPrint.ImageSize);
  
       try
          tagVariant(varBuffer).vt    := VT_UI1 or VT_BYREF; // 0x4011
          tagVariant(varBuffer).pbVal := Pointer(imgBuff);
  
          if fingerPrint.getData(varBuffer) then
          begin
               // success
          end;
       finally
          FreeMem(imgBuff);
       end;
  end;
  </code></pre>
  
  <p>another approach:</p>
  
  <pre><code>procedure GetImgData();
  var varBuffer : OleVariant;
      tagV : TVariantArg;
      imgBuff : PByteArray;
  begin
       GetMem(imgBuff, fingerPrint.ImageSize);
  
       try
          tagV.vt    := VT_UI1 or VT_BYREF; // 0x4011
          tagV.pbVal := Pointer(imgBuff);
  
          varBuffer  := OleVariant(tagV);
  
          if fingerPrint.getData(varBuffer) then
          begin
               // success
          end;
       finally
          FreeMem(imgBuff);
       end;
  end;
  </code></pre>
  
  <p>getData is not returning true using the parameter i'm sending. Sent my executable to support and told me that API is getting 0x400C (VT_VARIANT or VT_BYREF) instead of 0x4011.</p>
  
  <p>Anything wrong with my Code? </p>
  
  <p>Please Help!</p>
  
  <p>UPDATE:</p>
  
  <p>here's from dispinterface</p>
  
  <pre><code>function GetData(var ImageData: OleVariant): WordBool; dispid 23;
  </code></pre>
  
  <p>from Component Wrapper</p>
  
  <pre><code>..
  function GetData(var ImageData : OleVariant): WordBool;
  ..
  function TFingerPrint.GetData(var ImageData : OleVariant): WordBool;
  begin
    Result := DefaultInterface.GetData(ImageData);
  end;
  </code></pre>
  
  <p>C++ declaration</p>
  
  <pre><code>BOOL getData(const VARIANT FAR&amp; imgData)
  </code></pre>
  
  <p>UPDATE 20140313</p>
  
  <p>Our supplier sent new OCX to handle data received from Delphi.</p>