Xojo2024R3.1: URLConnection.ContentReceived - MessageBox not showing

One of the WebPages has URLConnection object in the tray at the bottom, in the ContentReceived event there is some that it is supposed to display message using MessageBox.
Example:

#Pragma Unused URL
#Pragma Unused HTTPStatus

If content.IndexOf("token")>0 Then  
  Var d As New Dictionary  
  d = ParseJSON(content)  
  MessageBox "Token value:" + d.Value("token")
Else
  Var vMsg As String = "Password Reset/Invitation " + content
  MessageBox vMsg
End If

I can put the breakpoint there and I see the vMsg populated but MessageBox does not work as usual, no message is presented on the screen. This code worked in Xojo2018.

I can place WebLabel with name URLContentLable with the following code:

URLContentLabel.Text = vMsg

and I get the content displayed.

So… You’re just getting lucky that the label is set correctly. Events of sockets run on the main thread which means the web framework has no way to know which session to send to. I think what you’ll find is that if there was more than one session, the label only gets set some of the time but not all.

You’ll need to either subclass URLConnection so that it knows which session it came from or use a messaging queue so the correct session can pick it up later.

1 Like

Actually the URLConnection is the super class of WebConnection that belongs to the WebPage in question. I am just looking for confirmation that it is “normal” in Xojo2024R3.1 that the MessageBox is no longer working. If it is “normal” that is OK with me, I can use the label. However, I would like to know for sure rather than make it up on my own :wink:

If however this is a bug I would like to report it with the hope that it will be fixed.

You stated that you’re using a URLConnection in the original post. If you are l, try using the WebConnection class instead. That’s probably set up to do what you want.

Greg, the “WebConnection” is just a name of this, the “URLConnection” is the superclass.
There is no build in class with the name “WebConnection”.

Ok. So

  1. add a class to the navigator, call it something you’ll remember.

  2. Set its super to URLConnection

  3. Add a private property mSession as String

  4. Add a Constructor with the code mSession = Session.Identifier

  5. Implement the events and right click on each event and click Create Event Definition from Event (or whatever it’s called)

  6. In each event, you’ll need code like this:
    Var ctx as new webSessionContext(mSession)

  7. Then you’ll need code to raise the event. So for Error, you’d write:
    RaiseEvent Error(e)

The context will cause the session to be valid while the context property exists.

From now on you use this class when you need access to the session it came from.

The advantage of doing it this way is that ctx will be nil if the session no longer exists. So if the user closes their browser you can just check to see if session is nil.

Here’s an example of what that looks like:

WebURLConnection Example.xojo_binary_project.zip (8.4 KB)

Thank you, I will take a look.

I was able to go over the example and learned something new for sure. I just need now to see how to use it in real app.
In the meantime two messages popped up when I was opening your sample project:


Btw,
The first message seems to be confusing to me as I am using latest available Xojo2024R3.1
The second message says something about item no longer supported in my version of Xojo which contradicts the first message.

yeah, I’m using a beta so you can ignore that.

In any places where you have code like this:

var c as new URLConnection

you’d instead use

var c as new WebURLConnection

If you’ve dragged a URLConnection onto a WebPage, just change its super to WebURLConnection

OK, great, thank you, I will see if this will allow MessageBox or Toast message then.
I will let you know.

Greg, thanks again for taking time and providing me with the solution. I have implemented new class into the web app I am working on and the MessageBox now works.

1 Like