I did a quick Google search but found no existing standard so I decided to simply describe one and publish it in the hope that others will find it useful and adhere to it.

I did a quick Google search but found no existing standard so I decided to simply describe one and publish it in the hope that others will find it useful and adhere to it.
http://blog.dummzeuch.de/2015/10/12/save-event-hooking-and-unhooking-for-delphi-ide-plugins/

Comments

  1. If I'm not supposed to override the class, then why is HandleEvent virtual?
    Also I find the leading underscores disturbing.

    ReplyDelete
  2. A nice addition would be an option to add my hook to a particular place in the chain. Esp. in the beginning or at the end. Right now I don't have an option.

    ReplyDelete
  3. Johan Bontes that's a good question. Originally I planned to have all objects that hook an event to inherit from that class and override that method. I reconsidered because that would significantly reduce the usability of it. As it is now, that method could simply be static.

    ReplyDelete
  4. Johan Bontes the code I posted for adding a hook can easily be extended to allow for inserting at the end (currently it inserts at the beginning). I tried to make it as easily usable as possible, that does not mean this is the only way to use that class. As long as the class remains unchanged, everything is fine. Also, there is probably an easier and more elegant way way to implement the procedures for hooking and unhooking. Especially since or should ideally work not just with TNotifyEvent type events but other types as well.
    There is lots of room for improvement, this is just a rough first draft to start a discussion on the subject. I have yet to test it with a real plugin in the IDE, all tests so far were inside a test program.

    ReplyDelete
  5. I have removed the virtual declaration.
    As for the leading underscores that "disturb" you: I find them much less annoying than the leading "A" that are the standard for parameters.

    ReplyDelete

Post a Comment