Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm wondering if that is somehow possible.

 

I've written a program which uses plugins,

now I want the PluginAPI to offer some custom Events.

Custom as in not some controls Events, rather a declared event which is then raised somewhere in my code.

 

Now I know only 2 solutions which I'd rather not use:

Move all the declarations of the Events to the class which is passed to the Addoninterface, which is usable by the addonwriter,

or pass the whole class where the Event declarations reside, also making any other public declared object accessible.

 

Here is an example:

Class MainProgram
   Public Event Bla()
End Class

Public Class cAddons
   Interface iHost
   End Interface

   Interface iAddon
       Sub Initialize(ByVal Host As iHost)
   End Interface
End Class

iAddon is the Interface which the addonwriter has to implement.

The API is provided though the iHost Interface,

which is where I want to make the Events, located in MainProgram, available.

Posted

Well I can add them there but I can't seem to assign an event to another.

 

Since the Event in the MainProgram class will be called,

I don't know how to make it accessible without exposing the whole MainProgramm class.

 

Class MainProgram
   Public Event Bla()
End Class

Public Class cAddons
   Interface iHost
       Event BlaCopy()
   End Interface

   Interface iAddon
       Sub Initialize(ByVal Host As iHost)
   End Interface
End Class

Now the addonwriter can access BlaCopy within the Initialize method through:

AddHandler Host.BlaCopy, [someFunction]

 

But the Event Bla & BlaCopy are still different Events.

Something like BlaCopy = Bla doesn't work,

I don't know how to connect them.

Posted

Yes the Events are raised (and declared) in the main program.

 

I want to give the addonwriter the ability to react to certain Useractions.

For example when the main program opens up the settingsform,

the Event SettingsOpened is raised.

 

Now I want to make the Event "SettingsOpened" available to the addonwriter,

so he knows when to add the addonsettings-controls to the settingsform.

Posted

I don't know if I understood everything correctly,

but it helped, it works now.

 

Instead of passing the Event to the addon (dll),

the addon calls a function (from the main program) which takes the address of the function which should be called and

then the mainprogram adds a handler for it.

 

I guess this method is the later possibillity you meant.

 

I don't understand the former one though.

Sure I could add an Event into the Addon Interface and add a handler for it in the main program,

but since the addon doesn't know when the settingsform is being opened by the mainprogram,

I don't know how this could be useful.

Posted

MainProgram needs to implement iHost

 

Class MainProgram
   Public Event Bla()
End Class

Public Class cAddons
   Interface iHost
       Event BlaCopy()
   End Interface

   Interface iAddon
       Sub Initialize(ByVal Host As iHost)
   End Interface
End Class

 

This won't work for the simple reason that MainProgram does not implement the iHost interface. If MainProgram implemented the interface, declared an event BlaCopy (which it would have to), and then you passed an instance of MainProgram to the addon class, then it would work correctly.

 

If you don't wish to pass MainProgram to your addon, create a proxy class which also implements iHost and which handles the MainProgram's BlaCopy event before raising its own BlaCopy. It looks like that's what you were trying to do with cAddons, but I'm not sure why the interfaces are nested types.

 

Good luck :cool:

Never trouble another for what you can do for yourself.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...