2
votes

I implemented an activeX control with Delphi. Now I want to add an events for it. I use the type library editor to add the event like this.

procedure OnActionMethod(ActionType: Integer; x1: Integer; 
  y1: Integer; x2: Integer; y2: Integer; param1: Double); dispid 213;

TezDICOMXOnActionMethod = procedure(ASender: TObject; 
  ActionType: Integer; x1: Integer; y1: Integer; x2: Integer; y2: Integer; 
  param1: Double) of object;

Everything compile fine.

Now I build a C# application, use that ActiveX control and try to implement an event handler.

private AxezDICOMax.AxezDICOMX the_ezdicom; // this is the activeX object

public void onActionHandler(object sender,long actiontype, 
    long x1, long y1, long  x2,long  y2, double param1)
{
  MessageBox.Show("abcabc" + x1.ToString() + x2.ToString());
}

private void MainForm_Load(object sender, System.EventArgs e)
{           
  the_ezdicom.OnActionMethod += new 
    AxezDICOMax.IezDICOMXEvents_OnActionMethodEventHandler(this.onActionHandler);
}

But the compiler complains with this error

Error 1  No overload for 'onActionHandler' matches delegate 
  'AxezDICOMax.IezDICOMXEvents_OnActionMethodEventHandler'
  OnActionMethodEventHandler

What did I do wrong? I didn't find the OnActionMethodEventHandler() anywhere on my Delphi source.

1
TObject is a Delphi type. You can't pass one of those over a COM boundary. Choose a different type for Sender, or drop that param altogether. The other obvious error is the C# long is 64 bits. Use int to match Delphi Integer. - David Heffernan
I'm sorry, may be this is my bad, but I can delete the ASender: Tobject in source file. I guess I should edit it with type library editor, but I don't know how. Please provide some more help. I've changed every "long" to "int", no different. - Khoa Le
Do they have anyway to work around this? I don't need to read any information from Asender anyway. - Khoa Le
You have to delete Sender on the C# side too. Make sure both sides match. Did you use stdcall on the Delphi side? - David Heffernan
No, on Delphi side, I use type library editor to add the event. It auto-generate the procedure and everything else. Now I delete Asender on the source code, compile again, it just appear again. I don't know how to delete it completely. - Khoa Le

1 Answers

1
votes

I use the auto - completion feature of Visual studio to know the true method should be.

void  onActionHandler(object sender, AxezDICOMax.IezDICOMXEvents_OnActionMethodEvent e)
{
    MessageBox.Show("abc");
}