title: Unable to pass a string from VBA (Excel) to my COM object
body: <p>I am experimenting with creating a COM interface for my application in order to allow eg. VBA to drive certain parts of my application.</p>
  
  <p>I have my COM library up and running and installed, even to the part where a routine called in Excel can be debugged in the Delphi IDE.</p>
  
  <p>Here's the VBA code that I activate from Excel using a button:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub TestAMQMOLE_OpenProject()
    Dim vConnection As String
    Dim vAMQM As Object
    Dim vAMProject As Object
  
    vConnection = "$(MYSRC)\LCCAMQM38\UnitTestData\AnalyseSortingAndGrouping"
    Set vAMQM = CreateObject("LCCAMQM_AX.LCCAMQM_Application")
    vAMQM.Connect
    Set vAMQMProject = vAMQM.OpenProject(vConnection) 'This parameter does not get through
    Set vAMQMProject.Active = True
    Set vAMQMProject = Nothing
  
  
    vAMQM.Disconnect
    Set vAMQM = Nothing
  
  
  End Sub
  </code></pre>
  
  <p>And the part in Delphi handling it looks like this:</p>
  
  <pre class="lang-pascal prettyprint-override"><code>function TLCCAMQM_Application.OpenProject(const aFolderOrAlias: WideString): ILCCAMQM_Project;
  begin
    try
      Result:=TLCCAMQM_Project.Create(aFolderOrAlias); // wrapper om TdmAMEditBase
    except
      SHowMessage(ExceptionToString(ExceptObject,ExceptAddr));
    end;
  end;
  </code></pre>
  
  <p>Where the code fails because the <code>aFolderOrAlias</code> parameter string is empty. I added the exception handler in order to debug outside the Delphi IDE. when debugging inside the IDE, the parameter string indeed appears as empty.</p>
  
  <p>I have also tried to pass the parameter as a <code>Variant</code>, or <code>const Variant</code> (and adjusting the type library accordingly), but in that case I get a <code>VT_RECORD</code> variant type (0x0024) which does not make any sense to me.</p>
  
  <p>Here is what the interface definition of the type library looks like.</p>
  
  <pre><code>....
   [
      uuid(EDD8E7FC-5D96-49F1-ADB7-F04EE9FED7B5),
      helpstring("Dispatch interface for LCCAMQM_Application Object"),
      dual,
      oleautomation
    ]
    interface ILCCAMQM_Application: IDispatch
    {
      [id(0x000000C9)]
      int _stdcall Connect(void);
      [id(0x000000CA)]
      int _stdcall Disconnect(void);
      [id(0x000000CB)]
      ILCCAMQM_Project* _stdcall OpenProject([in] BSTR aFolderOrAlias);
      [propget, id(0x000000CC)]
      HRESULT _stdcall Connected([out, retval] VARIANT_BOOL* Value);
    };
  
    [
      uuid(590DBF46-76C9-4877-8F47-5A926AFF389F),
      helpstring("LCCAMQM_Application Object")
    ]
    coclass LCCAMQM_Application
    {
      [default] interface ILCCAMQM_Application;
    };
  ....
  </code></pre>
  
  <p>I am fairly sure there must be a way to pass strings from VBA to COM objects. But after fiddling around for several hours I am lost :s.</p>