title: How to convert data types to call a COM procedure?
body: <p>I have a procedure that I need to call using COM, which is declared like this in C#:</p>
  
  <pre><code>void DoSomething (string param1, string[] param2, Object[] param3)
  </code></pre>
  
  <p>The Delphi declaration in the imported TypeLibrary is:</p>
  
  <pre><code>procedure DoSomething (param1: System.Widestring, 
                         param2: ActiveX.PSafeArray, 
                         param3: ActiveX.PSafeArray);
  </code></pre>
  
  <p>param1 is just a string.<br>
  param2 is an array of argument names, let's say: ['arg1', 'arg2'].<br>
  param3 is the according values for these arguments.</p>
  
  <p>Example: arg1: Double = 1.23, arg2: integer = 10.<br>
  This will result in:<br>
  - param2: ['arg1', 'arg2']<br>
  - param3: [1.23, 10]</p>
  
  <p>So far, I have this code to convert param2[] into a PSafeArray:</p>
  
  <pre><code>var param2: array of string;
      i: integer;
      va_param2: Variant;
      psa_param2: Activex.PSafeArray;
  begin
    SetLength (param2, 2);
    param2 [0] := 'arg1';
    param2 [1] := 'arg2';
    // Create VariantArray, copy data
    va_param2 := VarArrayCreate ([0, Length(param2)-1], varOleStr);
    for i := 0 to Length(param2)-1 do
      va_param2 [i] := param2 [i];
    // Convert VariantArray to PSafeArray
    psa_param2 := PSafeArray (TVarData (va_param2).VArray);
  end;
  </code></pre>
  
  <p>Now I should have the PSafeArray for param2.<br>
  But how can I do this for param3[] ?<br>
  There will be different data types, not only strings.  </p>
  
  <p>Since I cannot call the COM procedure before param2 and param3 are set up, I can also not be sure if the above code is doing what I need.<br>
  It runs, but am I doing these conversions correctly for passing the result to the above COM procedure?</p>