0

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.

4
  • Am I missing something? How can this work unless you use COM? Where are the C# interfaces? What led you to this solution? And why do you need JCL? What's wrong with CoCreateObject? Commented Jan 30, 2014 at 8:01
  • I'm not sure why this is COM interop, but if it helps the OP's source code appears to come from this article about .Net interop with the JVCL. Commented Jan 30, 2014 at 10:54
  • My understanding is that CoCreateObject requires the assembly to be in the GAC which I do not want. This example loads the assembly from the app directory. That is what JclDotNet unit affords me and why I was wanting to use it. And yes, I did build my example off the article that David M pointed out. Commented Jan 30, 2014 at 15:40
  • To add further, the only reason I mentioned COM was because of the ComVisible requirement, that it is late binding, and that I am receiving an OLE error. Perhaps I am overextending the reach of the term COM because I don't really know what is going on under the JCL hood, but the Delphi side is behaving as it does when I've worked with COM objects in the past. Commented Jan 30, 2014 at 21:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.