Late binding problems?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gregory_may

    #1

    Late binding problems?

    I want to prevent late binding of this statement:

    MyServerConnect ions(Myindex).c lient = Value


    But when I try with the code below, I get an editor error:
    "Expression is a value and therefor cant be the target of an assignment"

    CType(MyServerC onnections(Myin dex), PrivateServerCo nnectionStruct) .Client =
    value


    What is going on here?



    For reference, here is the struct definition:

    Private Structure PrivateServerCo nnectionStruct
    Dim client As System.Net.Sock ets.TcpClient
    Dim Connected_To_Se rver As Boolean
    Dim Connected_User_ Name As String
    Dim Remote_port_num As Integer
    Dim Remote_host_nam e As String
    Dim MessageQueue As Queue
    End Structure

    Dim MyServerConnect ions As New ArrayList



  • jvb

    #2
    Re: Late binding problems?

    I didn't test this to see if it actually works, but it doesn't throw
    the build error above...

    Call this routine...

    Private Sub SetMyClient(ByR ef ClientToSet As
    System.Net.Sock ets.TcpClient, ByVal Value As
    System.Net.Sock ets.TcpClient)
    ClientToSet = Value
    End Sub

    With this call...

    Me.SetMyClient( CType(MyServerC onnections(MyIn dex),
    PrivateServerCo nnectionStruct) .client, < System.Net.Sock ets.TcpClient[color=blue]
    >)[/color]

    Why did you decide to go with a Structure instead of a class? I don't
    believe you would have this problem with a class.

    Comment

    • gregory_may

      #3
      Re: Late binding problems?

      This is what I am doing inside the class. There is probably some other way
      to do this better, but I need a threadsafe way to get to
      "MyServerConnec tions". I am using the PublicServerStr uct as a "key" to look
      up a connection. I thought an array pointer would be easy, but I cant
      figure it out. So, below is a class that I am working on.

      I will paste the class below:


      Option Explicit On
      'Option Strict On
      Public Class COMMON_ServerCo nnections

      Public Structure PublicServerStr uct
      Dim Remote_port_num As Integer
      Dim Remote_host_nam e As String
      End Structure

      Private Structure PrivateServerCo nnectionStruct
      Dim client As System.Net.Sock ets.TcpClient
      Dim Connected_To_Se rver As Boolean
      Dim Connected_User_ Name As String
      Dim Remote_port_num As Integer
      Dim Remote_host_nam e As String
      Dim MessageQueue As Queue
      End Structure

      shared MyServerConnect ions As New ArrayList


      #Region " Properties "

      Public Property Client(ByVal PublicServerCon nection As
      PublicServerStr uct) As System.Net.Sock ets.TcpClient
      Get
      Dim Myindex As Integer =
      ReturnArrayInde xOfClient(Publi cServerConnecti on)
      If Not IsNothing(Myind ex) Then
      Return CType(MyServerC onnections(Myin dex),
      PrivateServerCo nnectionStruct) .client
      Else
      Return Nothing
      End If
      End Get
      Set(ByVal Value As System.Net.Sock ets.TcpClient)
      Dim Myindex As Integer =
      ReturnArrayInde xOfClient(Publi cServerConnecti on)
      If Not IsNothing(Myind ex) Then
      'Cant figure out how to get around late binding.
      MyServerConnect ions(Myindex).c lient = Value
      End If
      End Set
      End Property

      Public Property Connected_To_Se rver(ByVal PublicServerCon nection As
      PublicServerStr uct) As Boolean
      Get
      Dim Myindex As Integer =
      ReturnArrayInde xOfClient(Publi cServerConnecti on)
      If Not IsNothing(Myind ex) Then
      Return CType(MyServerC onnections(Myin dex),
      PrivateServerCo nnectionStruct) .Connected_To_S erver
      Else
      Return Nothing
      End If
      End Get
      Set(ByVal Value As Boolean)
      Dim Myindex As Integer =
      ReturnArrayInde xOfClient(Publi cServerConnecti on)
      If Not IsNothing(Myind ex) Then
      'Cant figure out how to get around late binding.
      MyServerConnect ions(Myindex).C onnected_To_Ser ver = Value
      End If
      End Set
      End Property

      Public Property Connected_User_ Name(ByVal PublicServerCon nection As
      PublicServerStr uct) As String
      Get
      Dim Myindex As Integer =
      ReturnArrayInde xOfClient(Publi cServerConnecti on)
      If Not IsNothing(Myind ex) Then
      Return CType(MyServerC onnections(Myin dex),
      PrivateServerCo nnectionStruct) .Connected_User _Name
      Else
      Return Nothing
      End If
      End Get
      Set(ByVal Value As String)
      Dim Myindex As Integer =
      ReturnArrayInde xOfClient(Publi cServerConnecti on)
      If Not IsNothing(Myind ex) Then
      'Cant figure out how to get around late binding.
      MyServerConnect ions(Myindex).C onnected_User_N ame = Value
      End If
      End Set
      End Property

      Public Property MessageQueue(By Val PublicServerCon nection As
      PublicServerStr uct) As String
      Get
      Dim Myindex As Integer =
      ReturnArrayInde xOfClient(Publi cServerConnecti on)
      If Not IsNothing(Myind ex) Then
      Return CType(MyServerC onnections(Myin dex),
      PrivateServerCo nnectionStruct) .MessageQueue.D equeue
      Else
      Return Nothing
      End If
      End Get
      Set(ByVal Value As String)
      Dim Myindex As Integer =
      ReturnArrayInde xOfClient(Publi cServerConnecti on)
      If Not IsNothing(Myind ex) Then
      CType(MyServerC onnections(Myin dex),
      PrivateServerCo nnectionStruct) .MessageQueue.E nqueue(Value)
      End If
      End Set
      End Property

      #End Region

      Public Function Add(ByVal RemoteHostname As String, ByVal
      RemotePortNumbe r As Integer) As PublicServerStr uct

      Dim ServerConnectio n As New PublicServerStr uct
      ServerConnectio n.Remote_host_n ame = RemoteHostname
      ServerConnectio n.Remote_port_n um = RemotePortNumbe r

      If ReturnArrayInde xOfClient(Serve rConnection) = -1 Then
      Dim NewServerConnec tion As New PrivateServerCo nnectionStruct
      NewServerConnec tion.Remote_hos t_name = RemoteHostname
      NewServerConnec tion.Remote_por t_num = RemotePortNumbe r
      NewServerConnec tion.MessageQue ue = New Queue

      MyServerConnect ions.Add(NewSer verConnection)
      End If
      End Function

      Public Sub Remove(ByVal PublicServerCon nection As PublicServerStr uct)
      Dim Myindex As Integer =
      ReturnArrayInde xOfClient(Publi cServerConnecti on)
      If Not IsNothing(Myind ex) Then
      MyServerConnect ions.Add(Myinde x)
      End If
      End Sub


      Public Function ReturnAllConnec tions() As ArrayList

      Dim MyConnections As ArrayList
      Dim PrivateConnecti on As PrivateServerCo nnectionStruct

      For Each PrivateConnecti on In MyServerConnect ions
      Dim ServerConnectio n As New PublicServerStr uct
      ServerConnectio n.Remote_host_n ame =
      PrivateConnecti on.Remote_host_ name
      ServerConnectio n.Remote_port_n um =
      PrivateConnecti on.Remote_port_ num
      MyConnections.A dd(ServerConnec tion)
      Next

      Return MyConnections
      End Function

      Private Function ReturnArrayInde xOfClient(ByVal PublicServerCon nection
      As PublicServerStr uct) As Integer
      Dim ServerConnectio n As New PrivateServerCo nnectionStruct

      Dim MyIndex As Integer = 0
      For Each ServerConnectio n In MyServerConnect ions
      MyIndex += 1
      If ServerConnectio n.Remote_host_n ame =
      PublicServerCon nection.Remote_ host_name Then
      If ServerConnectio n.Remote_port_n um =
      PublicServerCon nection.Remote_ port_num Then
      Return MyIndex
      End If
      End If
      Next

      'Cant find anythnig, so return ... -1

      Return -1
      End Function


      End Class


      Comment

      • gregory_may

        #4
        Re: Late binding problems?

        Ok, this appears to be working. Its the wierdest thing I have seen yet in
        ..Net:

        It appears that Directly manipulating the MyServerConnect ions ArrayList
        confuses everything. So, creating a "pointer", updating the pointer then
        copying back seems to be working. WHAT A PAIN.

        Is this a bug? This is not how you would think it should work.

        Public Function SetClient(ByVal PublicServerCon nection As
        PublicServerStr uct, ByRef MyClient As System.Net.Sock ets.TcpClient)
        Dim Myindex As Integer =
        ReturnArrayInde xOfClient(Publi cServerConnecti on)

        If Not IsNothing(Myind ex) Then
        Dim LocalPrivateSer ver As PrivateServerCo nnectionStruct
        LocalPrivateSer ver = CType(MyServerC onnections(Myin dex - 1),
        PrivateServerCo nnectionStruct)
        LocalPrivateSer ver.client = MyClient
        MyServerConnect ions(Myindex - 1) = LocalPrivateSer ver
        End If
        End Function


        "gregory_ma y" <None> wrote in message
        news:e%23xJN5$M GHA.2780@TK2MSF TNGP10.phx.gbl. ..[color=blue]
        >I want to prevent late binding of this statement:
        >
        > MyServerConnect ions(Myindex).c lient = Value
        >
        >
        > But when I try with the code below, I get an editor error:
        > "Expression is a value and therefor cant be the target of an assignment"
        >
        > CType(MyServerC onnections(Myin dex), PrivateServerCo nnectionStruct) .Client
        > = value
        >
        >
        > What is going on here?
        >
        >
        >
        > For reference, here is the struct definition:
        >
        > Private Structure PrivateServerCo nnectionStruct
        > Dim client As System.Net.Sock ets.TcpClient
        > Dim Connected_To_Se rver As Boolean
        > Dim Connected_User_ Name As String
        > Dim Remote_port_num As Integer
        > Dim Remote_host_nam e As String
        > Dim MessageQueue As Queue
        > End Structure
        >
        > Dim MyServerConnect ions As New ArrayList
        >
        >
        >[/color]


        Comment

        Working...