title: Delphi 7 to XE8 assigning binary ADO parameter values
body: <p>I'm converting a report that resides in a DLL to XE8 so that I can update our report control, which is problematic in Windows 10. In doing this, I've had to replace our ADO data access controls with the built-in ADO controls.</p>
  
  <p>The issues is that our data uses binary keys, and I've run into an issue assigning values to query parameters. In our code, the keys are passed around as strings, and assigned to the parameters and converted by the control at runtime.</p>
  
  <p>Previously, utilizing the old control, it utilized the Delphi DB unit which contains a method <code>.AsBlob</code> which was used in the assignment. See below...</p>
  
  <pre><code>Qry.Close;
  Qry.ParamByName('@Id').AsBlob := IdStringValue;
  Qry.Open;
  </code></pre>
  
  <p>In the control's implementation it handled setting the property, which called into <code>SetAsBlob</code>. See below...</p>
  
  <pre><code>Type TBlobData = string;
  </code></pre>
  
  <p>...</p>
  
  <pre><code>procedure TQryParameter.SetAsBlob(const Value: TBlobData);
  begin
    Self.DataType := ftVarBytes;
    Self.Value := StringToVarArray(Value);
  end;
  </code></pre>
  
  <p>Part of the issue is that Data.DB has changed <code>TBlobData = string;</code> to <code>TBlobData = TArray&lt;Byte&gt;;</code>.</p>
  
  <p>I've tried assigning these values to the query parameters following the same method used in the previous implementation, but it doesn't work.</p>
  
  <pre><code>Qry.Close;
  Qry.Parameters.ParamByName('@Id').DataType := ftVarBytes;
  Qry.Parameters.ParamByName('@Id').Value := ADODB.StringToVarArray(IdStringValue);
  Qry.Open;
  </code></pre>
  
  <p>I get a fairly generic MSSQL error due to the parameter mismatch, "Application uses a value of the wrong type for the current operation." </p>
  
  <p>The ADO query parameter is defined as <code>VarBytes</code> and the stored procedure accepts <code>BINARY(6)</code> for its only parameter so everything appears to be correct.</p>
  
  <p>I've tried casting <code>IdStringValue</code> from <code>String</code> to <code>AnsiString</code> prior to calling <code>StringToVarArray</code> but it makes no difference.</p>
  
  <p>Anyone know of a way to deal with this? Thank you.</p>