Arokh Posted April 23, 2008 Posted April 23, 2008 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. Quote
Administrators PlausiblyDamp Posted April 23, 2008 Administrators Posted April 23, 2008 An interface can contain event declarations, could you not just includse the event(s) as part of the iAddon interface? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Arokh Posted April 23, 2008 Author Posted April 23, 2008 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. Quote
Administrators PlausiblyDamp Posted April 25, 2008 Administrators Posted April 25, 2008 Perhaps I'm being a bit thick but I'm still not sure exactly what you are after. Are you wanting the main program to raise the events on behalf of the add ons or are you wanting the add ons themselves to raise the event? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Arokh Posted April 25, 2008 Author Posted April 25, 2008 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. Quote
Administrators PlausiblyDamp Posted April 25, 2008 Administrators Posted April 25, 2008 You could either have the add ons raise an event that the main program handles by simply re-raising the event or provide a callback routine to the add on as an alternate means of notification. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Arokh Posted April 25, 2008 Author Posted April 25, 2008 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. Quote
MrPaul Posted May 1, 2008 Posted May 1, 2008 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: Quote Never trouble another for what you can do for yourself.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.