Is there a trick to using an iterator with a subclass?

  1. 7 months ago

    Jason T

    6 Nov 2019 Testers, Xojo Pro Sydney, Australia

    I have a subclass of URLConnection. I want to get the new URLConnection ResponseHeaders property like this from the documentation:

    Dim connection As New URLConnection
    
    Var headers() As String
    For Each header As String In connection.ResponseHeaders
      headers.AddRow(header)
    Next

    The problem is, when I try to access myURLConnection.ResponseHeaders and iterate through the strings as per the documentation code, I get a TypeMismatchException. If I declare a regular URLConnection as per the sample code then it works as it should.

    My guess is that I might need to do something differently to access the ResponseHeaders property given that I have subclassed URLConnection?

    Bug in the docs, they should be Pairs, it only seems to work (by not breaking) as there is nothing in the list in that example.

    Try

    Var connection As New URLConnection
    
    Var s As String = connection.SendSync("GET", "https://www.google.com/", 5)
    
    Var headers() As Pair
    For Each header As Pair In connection.ResponseHeaders
      headers.AddRow(header)
    Next
  2. Julian S

    6 Nov 2019 Xojo Pro Answer UK
    Edited 7 months ago

    Bug in the docs, they should be Pairs, it only seems to work (by not breaking) as there is nothing in the list in that example.

    Try

    Var connection As New URLConnection
    
    Var s As String = connection.SendSync("GET", "https://www.google.com/", 5)
    
    Var headers() As Pair
    For Each header As Pair In connection.ResponseHeaders
      headers.AddRow(header)
    Next
  3. Jason T

    6 Nov 2019 Testers, Xojo Pro Sydney, Australia

    Perfect. Thank you Julian! :)

  4. 5 months ago

    FYI: Still not fixed in the docs ;)

  5. Julian S

    Jan 3 Xojo Pro UK

    Probably missed this one, seems to be happening quite often for simple/quick fixes Feedback Case #58180

  6. Christian S

    Jan 4 Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    I just made a request: Feedback Case #58755: array should be compatible to iterable interface

    Because if you have code expecting an iterable interface, you can't pass an array.

or Sign Up to reply!