| re: Reference problem
"Swandi Candra" <_swandi_candra_@hotmail.com> schrieb[color=blue]
> Hi all,
>
> I got a strange problem with classes in vb.net and
> hopefully someone can help me explain it.
>
> I got a simple class project called BaseObjects, with the
> following class, properties and methods
>
> Public Class StaffBase
> Private msFirstName As String
> Private msLastName As String
>
> Public Property FirstName() As String
> Get
> FirstName = msFirstName
> End Get
> Set(ByVal sFirstName As String)
> msFirstName = sFirstName
> End Set
> End Property
>
> Public Property LastName() As String
> Get
> LastName = msLastName
> End Get
> Set(ByVal sLastName As String)
> msLastName = sLastName
> End Set
> End Property
> End Class
>
> Then, I created another class project called
> BusinessObjects, where I added BaseObjects reference to it
>
> Public Class Staff
> Inherits BaseObjects.StaffBase
>
> Public Sub AssignName(Byval sFirstName As String,
> ByVal sLastName As String)
> FirstName = sFirstName
> LastName = sLastName
> End Sub
> End Class
>
> Afterward, I created a new window application project as
> the client (I added Staff reference to this new project)
>
> Private Sub Form1_Load(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles MyBase.Load
> Dim oStaff As BusinessObjects.Staff
>
> oStaff = New BusinessObjects.Staff()
> oStaff.AssignName("first", "last")
> MsgBox oStaff.FirstName
> oStaff = Nothing
> End Sub
>
> However, when I tried to build it, I got an error saying
>
> 'Public Property FirstName() As String' is declared in
> project 'BaseObjects.dll', which is not referenced by
> project 'WindowsApplication1.exe'
>
> My question is, why should I need a reference from
> BaseObjects? I thought BaseObjects had been inherited to
> BusinessObjects. Therefore, I only need BusinessObject's
> reference.
>
> Does anyone have a clue or explainations?[/color]
You also have to reference BaseObjects because it contains parts of the code
of the Staff class. In other words, the staff class is spread across two
libraries. One part is in the BaseObjects library, the other part in the
BusinessObjects library. You need both.
--
Armin |