Friend variable scope not accessable through object

D

Dominic

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top