AddHandler Confused?

I have a web project and have a dialog window that gets some information from the user which I need to pass back to the calling page. The dialog may be called from may different pages. I have the following code where I set the value of the notes field within the dialog before it is shown and the user can then edit this within the dialog. What I want to do is store the results when the dialog is closed so I have added an AddHandler and created a method called StoreNotes which then tries to store the notes back into the “rb” variables. I am getting errors when trying to do the AddHandler but not sure why or is their a better way to do this.

[code] dim dlg as new dlgColourNote

dlg.WhiteNote = rbWhiteNote
dlg.UltraVioletNote = rbUltraVioletNote
dlg.VioletNote = rbVioletNote
dlg.IndigoNote = rbIndigoNote
dlg.BlueNote = rbBlueNote
dlg.GreenNote = rbGreenNote
dlg.YellowNote = rbYellowNote
dlg.OrangeNote = rbOrangeNote
dlg.RedNote = rbRedNote
dlg.InfraRedNote = rbInfraRedNote
dlg.GeneralNote = rbGeneralNote

AddHandler dlgColourNote.dismissed, AddressOf StoreNotes

You would need to use the specific instance in AddHandler, i.e.:

AddHandler dlg.dismissed, AddressOf StoreNotes

Also make sure that the method signature of StoreNotes is correct, if there are no parameters in dismissed and no return type it should be

StoreNotes(sender as dlgColourNote)

if there are parameters and/or a return type it should be

StoreNotes(sender as dlgColourNote, OTHERPARAMS) as TYPE

where OTHERPARAMS are the parameters of the Dismissed event and TYPE is the return type of the event.

Thanks Jason, it was the “sender” I had forgotten about in my head.

If you’re not already aware, dynamic WebDialogs may be leaking memory.

<> Dynamic WebDialog Memory Leak - RemoveHandler and Sender=Nil

I did see the post but did not really understand what it was saying. My dialogs all have a button where I do a “self.close” which I thought would clear it out of memory for me. Are you saying this is not the case?

In my tests, Self.Close does not clear it out of memory. Your Web App is likely leaking memory every time it dynamically instantiates (aka As New) a WebDialog.

A relatively easy way to check is to add a WebTimer to your WebPage and in the Action Event paste this code:

//Thanks Christian Schmitz Dim c As Integer = 0 Dim o As Runtime.ObjectIterator = Runtime.IterateObjects While o.MoveNext Dim n As Object = o.Current If n IsA WebDialog Then c = c +1 End Wend // Self.Title = "WebDialog Count = " + Str(c) + " Object Count = " + Format(Runtime.ObjectCount, "###,###") + " Memory Used = " + Format(Runtime.MemoryUsed/1000, "###,###") + " KB"

While your WebApp is running, open and close a few dynamic WebDialogs on the WebPage with the WebTimer. My guess is that you’ll see all of the values displayed in the WebPage.Title continue to increase with each opening of another dynamic WebDialog.

Ah, yup mine leaks so I am going to have to change all the dynamic WebDialogs to use a control instead, what a pain.

I’m sorry to hear that but not surprised. <> has been Reviewed but not yet Verified. Feel free to participate in the Feedback case to get it more attention. :wink:

Note though that this “leaking” is confined to each session. If your use scenario is someone starting a session, using it only a little while, then closing it, then the leak shouldn’t be a problem. But if many users will continually use the same session all day, then it might become a problem (depending on how many dialogs are actually instantiated during the entire session).

Also note that the amount of memory leaked is proportionate to the number and type of controls on the dialog. You should estimate how much memory will be leaked in a typical usage scenario and decide if it’s worth the pain of refactoring your app.

Thanks Jay, I think what I may do in the short term is leave it as it is in the hope that by the time we get the app released and have a large number of users using it Xojo Inc will have fixed the issue. If they havent then I can tweak it all then.

This is now marked as Fixed:
<> Dynamic WebDialog Memory Leak - RemoveHandler and Sender=Nil
Hopefully we’ll see it in 2014r2.