Why do I need to use 'using' ?

After a few years neglecting RB in back trying to refresh my knowledge of Xojo.
In order to do that I decided to build a webservice that connects to Postgresql and a desktop app communicating with it (IOS is for later).

Thanks to Paul Lefevre’s webinar concerning webservices I managed to get the webservice connection to Postgresql going.

Now I am working on the desktop app, trying to make it connect to the WS. I managed to get it working but part of the code I don’t understand.
I peeked a lot at the files that were made public for the webinar and fore this case I looked at ‘EEiOS’

The following part when copied to my project did NOT work and I am hoping to get an explanation on why this did not want to compile:

I created a new class GeneralWS_Socket with super Xojo.Net.HTTPSocket
I add a Method ‘Hello’

Sub hello()
Self.Send(“POST”, “http://127.0.0.1:8080/special/Hello”)
End Sub

The HandleSpecialURL event on the webservice

Function HandleSpecialURL(Request As WebRequest) As Boolean
Dim data As Text = DefineEncoding(Request.Entity, Encodings.UTF8).ToText
Dim json As JSONItem

Select Case Request.Path
Case “Hello”
json = RespondToHello
Case “GetBasisPrijzen”
json = GetBasisPrijzen

'Case “GetCustomer”
'json = GetCustomer(data)

'Case “UpdateBasisPrijzen”
'json = UpdateCustomer(data)

Case Else
// Do not process request
Return False
End Select

// Send back data
Request.Print(json.ToString)

Return True
End Function

The respondtoHello method on the Webservice

Function RespondToHello() As JSONItem
Dim jsonResults As New JSONItem
jsonResults.Value(“Hello”) = “Who’s calling ?”
Return jsonResults
End Function

Until here everything worked: I could test the method in Safari and got {“Hello”:“Who’s calling ?”}

Now I subclassed the GeneralWS_Socket in my ConnectWS window and called it WS_Connect
I added a PageReceived Event handler

Sub PageReceived(URL as Text, HTTPStatus as Integer, Content as xojo.Core.MemoryBlock)
Dim jsonData As Text = TextEncoding.UTF8.ConvertDataToText(Content)

Dim json as Dictionary
json = Data.ParseJSON(jsonData)

if json.HasKey(“DBError”) Then
MsgBox(json.Value(“DBError”))
Elseif json.HasKey(“Hello”) Then
Self.lbl_feedback.Text =json.Value(“Hello”)
end if
End Sub

and this I could not get to compile

got 2 errors on this piece of code:

1 The item could not be found: TextEncoding.UTF8
2 The item could not be found: Data

Much cursing and experimenting later I got it working like this

Sub PageReceived(URL as Text, HTTPStatus as Integer, Content as xojo.Core.MemoryBlock)
using Xojo.Core
using Xojo.Data

Dim jsonData As Text = TextEncoding.UTF8.ConvertDataToText(Content)

Dim json as Dictionary
json = Xojo.Data.ParseJSON(jsonData)

if json.HasKey(“DBError”) Then
MsgBox(json.Value(“DBError”))
Elseif json.HasKey(“Hello”) Then
Self.lbl_feedback.Text =json.Value(“Hello”)
end if
End Sub

so I had to explicitly state to use Xojo.Core and Xojo.Data.

I still don’t understand why I need to do this, maybe better said: I still don’t understand why i needed to say this while in EEiOS these statements are nowhere to be found and are not needed to compile.

Anyone cares to get me an AHA-moment ?

TIA

iOS uses the new framework exclusively while other apps use a mixture of old & new with the default being old. So you need to specify the full namespace of the new framework or use the “using” statement in your non-iOS apps. I prefer to use the full namespace so that autocomplete works.

You can use the full namespace for iOS apps, so cross-platform methods can be made.

Hope this makes sense.

Same here.

OKeeee… Is this somewhere to be found in a manual or in the online docs ? I mean where is it stated which namespaces are to be “fully qualified” in what environment. Would have saved me probably some curses…

Thanks Wayne & Bob (didn’t hear or see this mentioned in your training videos either (or I missed it , of course))

Maybe this will help?
http://developer.xojo.com/migratingtonewframework

The new framework and the concept of Using are described here:

The global (existing) framework is all documented at http://documentation.xojo.com/index.php/Category:Language_Reference. The new frameworks are documented at http://developer.xojo.com/home.

Where I use the new framework or iOS is have almost always used the fully qualified namespace. It eliminates confusion, IMO.

Currently the ONLY place you MUST use the new namespace is iOS. Every where else it’s optional unless you’re using the new data types or the new sockets.

If you’re just getting back into Xojo, I would recommend you avoid the new framework until you are comfortable with the rest of the changes made - IDE, workflow, etc. Only then should you tackle the new framework. Otherwise, it could become overwhelming. Unfortunately that means ignoring some of the webinars.

The new framework is in a transitional state, which means that for now, there are two distinct sets of documentation. The new framework is found under “iOS documentation”, since it is only mandatory for iOS.