How to handle a superclass' event Help.

  • Thread starter Thread starter Steve Long
  • Start date Start date
S

Steve Long

Hello,
I have a VB.NET class that raises a MapSet event that passes an argument of
type interop.MapObjects2.MapClass.

I have a C# class that inherits from this VB.NET class. How can I handle the
VB.NET event in the C# class?
In VB.NET, you would just write:
Handles MyBase.MapSet

I would appreciate any help on this.
Steve
 
Simple, just like this in the inherited class:

base.MapSet += new EventHandler(this.MapSetFunction)

Where "EventHandler" is the delegate that is specified for the MapSet event
and "MapSetFunction") is the method you wish the event to raise. The
"base." is not required if you are not overriding the event with a new
event.

-Noah Coad
Microsoft MVP & MCP [.NET/C#]
 
Cool. Let me try that. I tried overriding but the compiler complained with
the following error:

COM Interop registration failed. Type library exporter encountered an error
while processing 'WeedPlugin1.CWeedPlugin.add_MapSet(value), WeedPlugin1'.
Error: Type library exporter can not load type MapSetEventHandler (error:
System.TypeLoadException: Could not load type MapSetEventHandler from
assembly DotNetPlugin, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=968e71ee5ce24c2c.).

As you can see, the event handler is MapSetEventHandler.
I'll see if it works the other way and let you know. Thanks for your help
btw.

Steve

Noah Coad said:
Simple, just like this in the inherited class:

base.MapSet += new EventHandler(this.MapSetFunction)

Where "EventHandler" is the delegate that is specified for the MapSet event
and "MapSetFunction") is the method you wish the event to raise. The
"base." is not required if you are not overriding the event with a new
event.

-Noah Coad
Microsoft MVP & MCP [.NET/C#]


Steve Long said:
Hello,
I have a VB.NET class that raises a MapSet event that passes an argument of
type interop.MapObjects2.MapClass.

I have a C# class that inherits from this VB.NET class. How can I handle the
VB.NET event in the C# class?
In VB.NET, you would just write:
Handles MyBase.MapSet

I would appreciate any help on this.
Steve
 
Okay, so I'm getting the error below whether I override the VB.NET event or
if I just add the event handling in the inherited class. If I just simply
add the event handling in the inherited class (as Noah suggested), I get the
error in VB6 when I instantiate the obejct. If I override the event, I get
the same error when I compile (the compiler throws the error).

In VB.NET, I had orginally just declared the event and let the compiler
implicitly declare the event handler. Then I changed it to declaring the
event handler and then the event using the following syntax:

Public Delegate Sub MapSetEventHandler(ByRef map As interop.MapObjects2.Map)

Public Event MapSet As MapSetEventHandler

I get the same error either way. Anybody know why I might be getting this
error? I have deleted the assemblies and .pdb files and recompiled several
times to no avail.

Steve

Steve Long said:
Cool. Let me try that. I tried overriding but the compiler complained with
the following error:

COM Interop registration failed. Type library exporter encountered an error
while processing 'WeedPlugin1.CWeedPlugin.add_MapSet(value), WeedPlugin1'.
Error: Type library exporter can not load type MapSetEventHandler (error:
System.TypeLoadException: Could not load type MapSetEventHandler from
assembly DotNetPlugin, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=968e71ee5ce24c2c.).

As you can see, the event handler is MapSetEventHandler.
I'll see if it works the other way and let you know. Thanks for your help
btw.

Steve

Noah Coad said:
Simple, just like this in the inherited class:

base.MapSet += new EventHandler(this.MapSetFunction)

Where "EventHandler" is the delegate that is specified for the MapSet event
and "MapSetFunction") is the method you wish the event to raise. The
"base." is not required if you are not overriding the event with a new
event.

-Noah Coad
Microsoft MVP & MCP [.NET/C#]


Steve Long said:
Hello,
I have a VB.NET class that raises a MapSet event that passes an
argument
of
type interop.MapObjects2.MapClass.

I have a C# class that inherits from this VB.NET class. How can I
handle
the
VB.NET event in the C# class?
In VB.NET, you would just write:
Handles MyBase.MapSet

I would appreciate any help on this.
Steve
 
Back
Top