I am basically trying to do:
Passing strongly typed arguments in .NET COM interop
But using Delphi and JCL to do it. I am admittedly NOT a COM guru and have done searches but can't quite find an answer to what I am trying to do. I have C# with this:
using System.Runtime.InteropServices;
namespace Example1ClassLibrary
{
[ComVisible(true)]
public class Example1
{
public Example1Obj AddByObj(Example1Obj Obj)
{
var ret = new Example1Obj();
ret.XVal = AddFunction(Obj.XVal, Obj.YVal);
ret.YVal = 0;
return ret;
}
}
[ComVisible(true)]
public class Example1Obj
{
public int XVal;
public int YVal;
}
}
And Delphi:
procedure TfrmMain.FormCreate(Sender: TObject);
begin
Host := TJclClrHost.Create('v4.0.30319');
Host.Start();
Obj := Host.DefaultAppDomain.CreateInstance('Example1ClassLibrary', 'Example1ClassLibrary.Example1').UnWrap();
end;
procedure TfrmMain.Button4Click(Sender: TObject);
var
Pass: OleVariant;
Ret: OleVariant;
begin
Pass := Host.DefaultAppDomain.CreateInstance('Example1ClassLibrary', 'Example1ClassLibrary.Example1Obj').UnWrap();
Pass.XVal := StrToInt(EditX.text);
Pass.YVal := StrtoInt(EditY.text);
Ret := Obj.AddByObj(Pass);
EditResult.Text := Ret.XVal;
end;
When I click Button4, I get the
EOleSysError "The parameter is incorrect".
at the line:
Ret := Obj.AddByObj(Pass);
Is what I'm trying to do possible, and if so, what am I missing. Note: Simple types works fine so actually loading the assembly, creating the object, and calling a method with simple types works great.