Dave Nottage 557 Posted May 6, 2019 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
Stefan Glienke 2002 Posted May 6, 2019 Probably by calling Type.GetType(string) 1 Share this post Link to post
Rudy Velthuis 91 Posted May 7, 2019 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
Dave Nottage 557 Posted May 7, 2019 On 5/6/2019 at 5:17 PM, Stefan Glienke said: Probably by calling Type.GetType(string) How does one do that from Delphi? Share this post Link to post
Stefan Glienke 2002 Posted May 8, 2019 https://stackoverflow.com/a/1395915/587106 1 Share this post Link to post
David Heffernan 2345 Posted May 8, 2019 2 hours ago, Stefan Glienke said: https://stackoverflow.com/a/1395915/587106 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
Stefan Glienke 2002 Posted May 8, 2019 (edited) 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 May 8, 2019 by Stefan Glienke Share this post Link to post
Dave Nottage 557 Posted May 8, 2019 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
Stefan Glienke 2002 Posted May 8, 2019 (edited) 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 May 8, 2019 by Stefan Glienke Share this post Link to post
Dave Nottage 557 Posted May 14, 2019 (edited) 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 May 14, 2019 by Dave Nottage Share this post Link to post