Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Object types
Message
 
To
28/10/2002 14:49:29
Rex Mahel
Realm Software, Llc
Ohio, United States
General information
Forum:
ASP.NET
Category:
Object Oriented Programming
Title:
Miscellaneous
Thread ID:
00716148
Message ID:
00716238
Views:
17
Without seeing your code, here is an example of how to create a method that receives a parent object reference but a Child object reference is actually sent. This won't give you any errors and is acceptable code.
Public Class ParentClass
End Class

Public Class Child1Class
    Inherits ParentClass
End Class

Public Class MyMethods
    Public Sub Meth1(ByVal p1 As ParentClass)
    End Sub

    Public Sub Meth2()
        Dim x As Child1Class
        ' This works
        Meth1(x)
    End Sub
End Class
However, the following is not valid because you can't pass a parent object where a child object is expected:
Public Class ParentClass
End Class

Public Class Child1Class
    Inherits ParentClass
End Class

Public Class MyMethods
    Public Sub Meth1(ByVal p1 As Child1Class)
    End Sub

    Public Sub Meth2()
        Dim x As ParentClass
        ' This won't work
        Meth1(x)
    End Sub
End Class
>All,
>
>I have a business object base class which I subclass for my specific applications. These subclasses are the base class for all application business objects. I read in ".Net for Visual Foxpro Developers" about polymorphism and virtual methods, that given 3 classes, A, B, and C where B and C are subclasses of A, that a variable of type A can hold a reference to either classes B or C. I have created a function to which I wish to send a reference to a business object. In the function I have a parameter of type ODHBusinessObjectBase to which I am sending an object, by reference, of type CAudienceType which is a subclass of ODHBusinessObjectBase. I get an error that option strict on disallows implicit conversion from ODHBusinessObjectBase to CAudienceTypes.
>
>How can I create a generic function to take a reference to a specific class?
>
>TIA
>
>Rex
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Reply
Map
View

Click here to load this message in the networking platform