AddHandler Question

When I compile the webapp

If mTest = True Then AddHandler DisplayMsg.NotificationDismissedAfter, WebPage1.NotificationDismissedAfter Else AddHandler DisplayMsg.NotificationDismissedAfter, WebDialog1.NotificationDismissedAfter End

I am getting this compile error:-

Error: Type "WebDialog1" has no member name "NotificationDismissedAfter"

I had already added “NotificationDismissedAfter” as method in WebDialog1 and had already set it as public. Why am I still getting this error?

http://developer.xojo.com/addhandler

If you have already added a handler to the dialog in the IDE, you cannot do it again with AddHandler.

Try:

If mTest = True Then AddHandler DisplayMsg.NotificationDismissedAfter, AddressOf WebPage1.NotificationDismissedAfter Else AddHandler DisplayMsg.NotificationDismissedAfter, AddressOf WebDialog1.NotificationDismissedAfter End

In case it’s not clear from Frederick’s code snippet, you need to use AddressOf (or WeakAddressOf) to assign a method to an event.

I had converted my codes to using delegate but I am still getting the same compilation error when pointing to a WebDialog Method.

Attached please find the delegate project:-https://xojo.io/78d92eec6b91

Any comments are greatly appreciated.

link text

Sorry, supposed to insert the link tag. :slight_smile:

You need to create an instance of WebDialog1 before you can reference its methods:

   Dim w As New WebDialog1
    d = AddressOf w.Method1

[quote=309752:@Andrew Lambert]You need to create an instance of WebDialog1 before you can reference its methods:

Dim w As New WebDialog1 d = AddressOf w.Method1 [/quote]
Thank you for saving my headaches.

May I know why I do not need to reference the method in Webpage? Sorry for asking all this as I am very new in this area.

If your webpages have implicit instance, they are preloaded, so they already exist. If you switch off implicit instance, you will have to do the same as WebDialog.

Note that because webpages are preloaded, they display faster, but the drawback is someone can use the browser developer tools to access them.

If for instance you want to limit access to certain pages, for instance with an app that requires login, it is better to switch off implicit instance in the IDE for all WebPages.

Attached is the sample project for easy reference.

In the WebDialog1, lets say I have a WebTextField1 with values entered. When I invoked the delegate method,

Dim d As MethodCaller //delegate Dim w As New WebDialog1 d = AddressOf w.Method1 d.Invoke

is there any ways to read the existing value of WebTextField1.Text? Currently, my WebApp is showing an empty Text String Value. Probably I think it is due to creating a “New” instance of WebDialog1. Is it possible to copy the contents from the existing WebDialog1?

At this point in time, I really have no idea how to get the existing value due to my limited knowledge. Your help is greatly appreciated again.

Instead of instantiating the webdialog with a dim, use a property on your webpage, so you can call method1 directly :

W as Webdialog1 is the property added to the WebPage, and you instantiate the webdialog as such :

W = New WebDialog W.show

Then all you need to do is :

If W <> nil then w.Method1 Msgbox w.TextField1.Text end if

Hello Michel,

[quote=309787:@Michel Bujardet]If W <> nil then
w.Method1
Msgbox w.TextField1.Text
end if[/quote]

I am able to implement these codes in my WebApp

w = New WebDialog1 w.show

But I do not know where should I place your recommended codes in my rest of my WebApp.

If W <> nil then w.Method1 Msgbox w.TextField1.Text end if

I had tried placing the codes in the possible methods but I am still getting compilation errors. Attached is my revised project file and I hope that you may send me a fish for this time instead. :slight_smile:

I may have not understood what you were after.

All you have to do to call a method on the same webpage or webdialog is simply to enter its name. No need for delegate.

See https://dl.dropboxusercontent.com/u/17407375/Delegate3.xojo_binary_project

[quote=309809:@Michel Bujardet]I may have not understood what you were after.

All you have to do to call a method on the same webpage or webdialog is simply to enter its name. No need for delegate.

See https://dl.dropboxusercontent.com/u/17407375/Delegate3.xojo_binary_project[/quote]
Perhaps, I had confused you. Sorry for not being able to give you a clear picture in the first place.

As you can see from my test project, WebDialog Button1 is calling the method directly and I can get the value TextField1.Text
But for WebDialog Button2, I Need to call a Module and display the value of TextField1.Text instead. Cos ultimately I will be converting the WebDialog to a subclass and I will not be able to call the method directly as each new Webdialog will be showing different textfields

Attached, Please see the updated project file again

You don’t need a module for a subclass.

However, it is easy to convert a method for a module. All you have to do is to pass the Webdialog to it :

[code]Sub DisplayText(wd as WebDialog1)

Msgbox wd.TextArea&.Text

end sub[/code]

And you would call it as such :

DisplayText(W) or DisplayText(self) 'if from the Webdialog

In Subclasses methods are automatically exposed to the instance if you make them public. So Method1 is automatically available in w.

Could you try to describe what you want to do as a subclass ?

Please explain more fully.

[quote=309875:@Michel Bujardet]You don’t need a module for a subclass.

However, it is easy to convert a method for a module. All you have to do is to pass the Webdialog to it :

[code]Sub DisplayText(wd as WebDialog1)

Msgbox wd.TextArea&.Text

end sub[/code]

And you would call it as such :

DisplayText(W) or DisplayText(self) 'if from the Webdialog

In Subclasses methods are automatically exposed to the instance if you make them public. So Method1 is automatically available in w.

Could you try to describe what you want to do as a subclass ?

Please explain more fully.[/quote]

This is actually what I am trying to accomplished. I had converted my webdialog to a subclass (I do not know whether I had called it correctly or not). I think calling a method directly within the webdialog would not be possible(I hope that I am wrong) :(.
This is the revised project to give you my exact idea.link text

when save button is clicked, I am unable to save the record correctly as the textfield1.value is empty.

Webdialogs, WebPages, and in desktop Dialogs and windows cannot be subclassed.

You are wrong. You are actually calling the method from the webdialog in your previous project. A method can primarily be called from its class, and from other places if it is public. Protected is kind of public, but you have to call it from outside with the name of the instance as prefix :

w.Method1[quote=309878:@Alvin Lim]when save button is clicked, I am unable to save the record correctly as the textfield1.value is empty.
[/quote]

I don’t see any button on your WebDialog, but if it were on it, I believe it should work.

Your DisplayText method should be :

Public Sub DisplayText() Msgbox TextField1.Text End Sub

You don’t prefix calls when the method is on the class.

[quote=309881:@Michel Bujardet]Webdialogs, WebPages, and in desktop Dialogs and windows cannot be subclassed.

You are wrong. You are actually calling the method from the webdialog in your previous project. A method can primarily be called from its class, and from other places if it is public. Protected is kind of public, but you have to call it from outside with the name of the instance as prefix :

w.Method1

I don’t see any button on your WebDialog, but if it were on it, I believe it should work.

Your DisplayText method should be :

Public Sub DisplayText() Msgbox TextField1.Text End Sub

You don’t prefix calls when the method is on the class.[/quote]

The Save button is in the MainframeDialog. The WebDialog1 is subclass from MainframeDialog. I had make the method public in WebDialog1, but I am still getting an empty value when calling the method.

Hello Michel, after reading your reply again, it seems that you are still referring to my old project. Please see this project It should give you the idea of what I am trying to accomplish.

You should be able to see the save button in MainframeDialog and I did not call the method directly from webdialog1.

Thank you,.