We are trying to make a C# program as A COM object and acces it from a
unmanaged Delphi program and this gives us some problems.
In the program below we have declared two public members Command1()
and Command2()that we want to access from Delphi, and this works fine.
We also declared two Delegates OnDol and OnDol2, which is a function
pointer to two function in our Delphi program. As sune as our C#
program reach one of thise delegates we get the error message: "Not
inplemented". The delegates are not null, but obvious not set to point
to the function in the Delphi program. Is the any errors in the C#
code below? Does any have expirence with how to do this "connection in
"Delphi"
using System.Runtime.CompilerServices;
using System.Reflection;
using System.Diagnostics;
namespace DotNetAsCom
{
/// <summary>
/// Summary description for Dolphin.
/// </summary>
public delegate void OnDol2Delegate(int X);
[InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIDispatch)]
public interface IDolphinEvents
{
void OnDol(object sender, System.EventArgs e);
void OnDol2(int X);
}
[InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIDispatch)]
public interface IDolphin
{
void Command1();
void Command2();
}
[ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces("DotNetAsCom.IDolphinEvents")]
public class Dolphin : IDolphin
{
public Dolphin()
{
}
public event System.EventHandler OnDol;
public event OnDol2Delegate OnDol2;
protected void DoDol()
{
MessageBox.Show ("DoDol called", "DotNetAsCom",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
if (OnDol != null)
{
MessageBox.Show ("DoDol code body entered", "DotNetAsCom",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
OnDol(this, new System.EventArgs());
}
}
protected void DoDol2()
{
MessageBox.Show ("DoDol2 called", "DotNetAsCom",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
if (OnDol2 != null)
{
MessageBox.Show ("DoDol2 code body entered", "DotNetAsCom",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
OnDol2(5);
}
}
public void Command1()
{
MessageBox.Show ("Command1 called", "DotNetAsCom",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
DoDol();
}
public void Command2()
{
MessageBox.Show ("Command2 called", "DotNetAsCom",
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
DoDol2();
}
}
}
Regards
Henrik