Friend variable scope not accessable through object

Discussion in 'ASP .Net' started by Dominic, Nov 3, 2004.

  1. Dominic

    Dominic Guest

    I have 'project1' whereas I use the classes/modules of that assembly
    in 'project2'. If an item in project1 is declared as 'object', the
    properties and methods on that object declared as friend are not
    accessable. A simple example:
    create a class library 'project1' with the following:

    Public Class myPublicClass
    Friend Function myFriendFunction()
    End Function
    End Class

    Public Class myTestClass
    Public TestScope As Object

    Public Sub New()
    TestScope = New myPublicClass
    TestScope.myFriendFunction()
    End Sub
    End Class


    Now compile/create the assembly. In another project try:
    dim TestProject1 as project1.myTestClass = new project1.myTestClass

    This will error as: Public member 'myFriendClass' on type
    'myPublicClass' not found

    Now here is the catch! In project1.myTestClass, change the
    declaration type of TestScope from 'Object' to 'myPublicClass' and
    execute the test case again. It works! Why doesn't the first
    scenario work and the second does? And this is just a simple example,
    my real-world situation dictates that the variable may be one of
    several different classes so it's type would be the generic 'Object'.
    Please don't offer the solution of typing the variable as the specific
    class. Any help/explanation is appreciated.
     
    Dominic, Nov 3, 2004
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bruce Hodge
    Replies:
    0
    Views:
    507
    Bruce Hodge
    Feb 15, 2006
  2. Jim Walseth
    Replies:
    0
    Views:
    385
    Jim Walseth
    Oct 23, 2003
  3. Mike
    Replies:
    1
    Views:
    536
    Juha Nieminen
    Jan 16, 2011
  4. Mike
    Replies:
    6
    Views:
    957
  5. william

    web service is not accessable

    william, Nov 16, 2007, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    194
    william
    Nov 16, 2007
  6. David Filmer
    Replies:
    19
    Views:
    527
    Kevin Collins
    May 21, 2004
  7. Andrew Falanga
    Replies:
    2
    Views:
    393
    Andrew Falanga
    Nov 22, 2008
  8. Replies:
    1
    Views:
    120
    Chris Angelico
    Mar 18, 2014
Loading...