Inheritence Question

R

Rob Panosh

Hello,

The sample Sub below in Class database accepts a parameter typed as
AdvancedSoftwareDesigns.Table. The problem I am having is if I derive from
AdvancedSoftwareDesigns.Table, i.e. - CLASS myTable INHERITS
AdvancedSoftwareDesigns.Table, so I can add functionality to the class.
When I try to add my derived class using oDatabase.AddTable( oMyClass ) I
get compile error becuase I have Strict ON. If I CTYPE it to
AdvancedSoftwareDesigns.Table I no longer get compile error. The question
I have is if I add any Instance Variable to my derived class will they be
lost when I CTYPE? Also can I cast the object back to be myTable? Or
should I be using a different approach?

Sample Code:
--------------

Public Class Database
Inherits System.Object

Public Sub addTable( byRef Table as AdvancedSoftwareDesigns.Table )
me.tablecollection.Add( Table )
End Sub

End Class


Public Class myTable
Inherits AdvancedSoftwareDesigns.Table

Public someVar as String
Private anotherVar as String

....


End Class


Thanks,
Rob Panosh
 
C

CJ Taylor

I've never had a problem with that...

Using CType still retains all the info for the derived class. How does that
work, we don't want to get into that. =)

CJ
 
S

Stephen Martin

The sub takes the Table parameter by reference. This means that the
reference could be changed to a different object that is not necessarily of
type myTable (ergo the implicit conversion of the returned reference). There
isn't really any point in having the parameter ByRef so change it to ByVal.
 

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

Top