Jump to content
Dave Nottage

Using GetMethod functions in the .NET COM interop

Recommended Posts

I've been successfully (up until now) using the .NET COM interop:

 

  https://raw.githubusercontent.com/project-jedi/jcl/master/jcl/source/windows/mscorlib_TLB.pas

 

(as part of JCL) however I'm having trouble invoking a method that is declared with a number of overloads in an assembly. It raises an error "Method xxxx not found", and I'm assuming it is because it does not know which method to use.  Regardless, I'd like to be able to use one of the GetMethod calls to find the right overloaded method, probably using GetMethod_5, since I just want to find the method by the name and the parameter types.

 

The question is: how do I go about passing the correct values for the types parameter? If it were using reflection in C#, it would use typeof, so what might be the equivalent in Delphi?

Share this post


Link to post
On 5/6/2019 at 9:47 AM, Stefan Glienke said:

Probably by calling Type.GetType(string)

In Delphi? I must admit the last time I did something with .NET and native Delphi was a long time ago, but can we do GetType() or similar in Delphi?

Share this post


Link to post
2 hours ago, Stefan Glienke said:

I think that post is about accessing a COM object exposed by a .net assembly. But I think that the asker is embedding the .net runtime via its COM interface. So I expect that there is a way to obtain Type and call methods on it, but who wants to scour 32kloc and learn how to use that darn thing.

 

Surely the entire enterprise would be easier by exposing the target code with a .net layer, e.g. a COM wrapper of the target code.

Share this post


Link to post
1 hour ago, David Heffernan said:

I expect that there is a way to obtain Type and call methods on

And that is what I don't think because it is said in that answer that you cannot call static methods via COM - but I agree that putting all that code into the C#/.NET side and just call it might be easier.

 

Edit: You obviously want to call the method that you are trying to get and pass the parameters to it that you need the types for - so ask those instances that you are planning to pass to the method for their type.

Edited by Stefan Glienke

Share this post


Link to post
2 hours ago, Stefan Glienke said:

so ask those instances that you are planning to pass to the method for their type

Can you clarify what this means?

 

2 hours ago, David Heffernan said:

I think that the asker is embedding the .net runtime via its COM interface.

Correct.

Share this post


Link to post
4 minutes ago, Dave Nottage said:

Can you clarify what this means?

You want to get some method via reflection - thats why you asking for calling GetMethod_5. Now that one requires you to pass the signature via an array of types.

What are you going to do with that? Obviously you want to then invoke that method, no?

But in order to do that you then need to pass the parameter values for that particular overload - what are those? You need to have some - ask them for their type (GetType)

Edited by Stefan Glienke

Share this post


Link to post
On 5/8/2019 at 11:37 PM, Stefan Glienke said:

You need to have some - ask them for their type (GetType)

I think I've found the way: using the GetType_2 method of _Assembly.

Edited by Dave Nottage

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×