HtmlEditor :  Phorum 5 The fastest message board... ever.

This is the discussion forum for the HtmlEditor. See also the HtmlEditor home page, where you can download the control, and the Documentation Wiki, a collaborative project for documenting the control.

Goto Thread: PreviousNext
Goto: Forum ListMessage ListNew TopicSearchLog In
Event handlers in CloseDocument
Posted by: Peter Wone (---.dyn.iinet.net.au)
Date: Saturday, 07-Jan-2006, 02:02:24

Correct me if I'm wrong but as far as I can see this excerpt from htmlsite.CloseDocument() cannot possibly be correct code.

container.Resize -= new EventHandler(this.Container_Resize);

The -= operator removes a delegate instance from the collection of delegates implied by an event declaration. The code above manufactures a NEW instance and it therefore won't be found, and therefore won't be removed. This code, though legal, has no effect other than slightly increasing transient memory consumption.

If you want to unhitch from the event you need to keep a reference to the delegate instance and pass that. So htmlsite needs a member

EventHandler containerResizeDelegateInstance;

which must be initialized in the constructor

containerResizeDelegateInstance = new EventHandler(Container_Resize);

You (un)bind it like this

container.Resize += containerResizeDelegateInstance;
container.Resize -= containerResizeDelegateInstance;

Re: Event handlers in CloseDocument
Posted by: Tim (---.gotadsl.co.uk)
Date: Saturday, 07-Jan-2006, 09:15:59

Your 2nd approach should work fine too; but although the code looks odd it is the documented way to remove an event handler if you haven't kept a reference to the delegate (which is the norm). I suppose the logic is that the "new" delegate references the same method.

Tim



Your Name: 
Your Email: 
Subject: 
Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically.
phD3T
This is a moderated forum. Your message will remain hidden until it has been approved by a moderator or administrator
This forum powered by Phorum.