I have a DLL written in C#, which I want to use in my Delphi application.
I was able to import the DLL correctly (using its TLB file) into Delphi. I can create an instance of that class from DLL, I can call its methods, all that works fine.
I don't know how I can register to receive events occurring in that DLL (it receives data from a physical device).
I have a C# DLL and a C# test app using that DLL where it is way simpler (it simply adds a handler for that event), but I can't achieve that in Delphi.
I have written my own small C# DLL where an event exists (in the same way as it does in the original DLL). Here is the code for it:
My C# DLL:
namespace ClassLibrary3
{
public class FlowDataEventArgsMine : EventArgs
{
public double Flow { get; set; }
}
public class Class3
{
public string Hello()
{
return "Hello World";
}
public event EventHandler<FlowDataEventArgsMine> FlowDataReceivedMine;
}
}
How this is used in a C# App:
c = new Class3();
c.FlowDataReceivedMine += new EventHandler<FlowDataEventArgsMine>(OnNewFlowDataReceivedMine);
private void OnNewFlowDataReceivedMine(object sender, FlowDataEventArgsMine e)
{
// this method is called when the event provides new flow data
}
In Delphi:
CL := TClass3.Create(NiL);
res0 := CL.Hello; //this works OK, I can call methods from that class
CL.FlowDataReceivedMine := MyMethodToBeCalled; //this is NOT OK - how can I register for that event? It's not even showing that event as a part of this Class
CL.Free;
Obviously, I tried to read every article, question and post I could find. I have a feeling that I read half of the Internet already, but I can't find anything which would point me to a solution.
Can anybody point me to a working example, where I can achieve the same in Delphi as what's simple in C# (I mean, simply adding a method to be called when an event happens)?
EDIT:
Isn't that really possible to receive any sort of info that an event was fired in the C# Dll when using it in my Delphi app? During research I encountered some info that exported class from C# DLL needs to implement some interface, and in my Delphi app I should implement the same interface and this would allow me to handle events from that DLL (but didn't found any full solution as example and what I found was not enough to make working solution for me).
This post looks promising, author stated that he was able to achieve that but unfortunately the steps given there don't work for me and step by step blog is not reachable anymore:
Exposing C# COM server events to Delphi client applications
Feels like running in circles and still not sure what is possible and what's not :/