Show code snippet - Using a QWeakReferenceCollection //A QWeakReferenceCollection containing QWeakReferences to QColorSchemes public class QColorSchemeCollection : QWeakReferenceCollection { //Default constructor public QColorSchemeCollection() {} //Adds a QWeakReference to the QColorScheme to the collection public void AddColorScheme(QColorScheme colorScheme) { this.AddObject(colorScheme); } //Removes the QWeakReference of the QColorScheme from the collection public void RemoveColorScheme(QColorScheme colorScheme) { this.RemoveObject(colorScheme, true); } //Raises the ColorsChanged event of //all QColorSchemes in the collection public void RaiseColorsChanged() { //iterate backwards because we remove //collected weak references QColorScheme tmp_oColorScheme; for (int i = this.Count - 1; i >= 0; i--) { //get the weak reference QWeakReference tmp_oReference = this[i]; if ((tmp_oReference != null) && (!tmp_oReference.Finalized) && (tmp_oReference.IsAlive)) { //raise the event if the //reference is still alive tmp_oColorScheme = (QColorScheme) tmp_oReference.Target tmp_oColorScheme.RaiseColorsChanged(); } else { //remove the item if the //colorscheme is collected this.RemoveAt(i); } } } }
//A QWeakReferenceCollection containing QWeakReferences to QColorSchemes public class QColorSchemeCollection : QWeakReferenceCollection { //Default constructor public QColorSchemeCollection() {} //Adds a QWeakReference to the QColorScheme to the collection public void AddColorScheme(QColorScheme colorScheme) { this.AddObject(colorScheme); } //Removes the QWeakReference of the QColorScheme from the collection public void RemoveColorScheme(QColorScheme colorScheme) { this.RemoveObject(colorScheme, true); } //Raises the ColorsChanged event of //all QColorSchemes in the collection public void RaiseColorsChanged() { //iterate backwards because we remove //collected weak references QColorScheme tmp_oColorScheme; for (int i = this.Count - 1; i >= 0; i--) { //get the weak reference QWeakReference tmp_oReference = this[i]; if ((tmp_oReference != null) && (!tmp_oReference.Finalized) && (tmp_oReference.IsAlive)) { //raise the event if the //reference is still alive tmp_oColorScheme = (QColorScheme) tmp_oReference.Target tmp_oColorScheme.RaiseColorsChanged(); } else { //remove the item if the //colorscheme is collected this.RemoveAt(i); } } } }
Application.AddMessageFilter(m_oMyMessageFilter);
Application.AddMessageFilter(new QWeakMessageFilter(m_oMyMessageFilter));