M
Mike
Hi All,
We are in the process of upgrading some VB6 code to .Net Specifically, we are re-writing some class definitions in the .Net environment to still be used in VB6. I think we have most of the stumbling blocks figured out, however, there is one design requirement due to poor programming that we need to implement. This requirement is to be able to have access to all child properties from its parent. Let's do a simple example that may illustrate this.
VB.Net Code
Public Class myBaseClass
Public myBaseClassProp As String
End Class
Public Class myDerivedClass
Inherits myBaseClass
Public myDerivedClassProp As String
End Class
From within VB6 I need to be able to access myBaseClss.myDerivedClassProp through code like
Dim md As New myDerivedClass
Dim mb as myBaseClass
Set mb=md
mb.myDerivedClassProp="test"
I did find the following blurb from the below website to slightly lead me in the right direction. However, it didn't give any examples or indications of actually how to go about doing this. I know if I can somehow override the Interfaces below, we can write our own implementation and use Reflections to get the property that we are looking for. I would also like to be able to do a mixture of early and late binding(which I don't know if it is possible) where all the regular properties are made available through intellisense and so that the application performs best.
The website/blurb is as follows:
http://msdn.microsoft.com/en-us/library/111chfb8(VS.80).aspx
In addition to exposing the interfaces that are explicitly implemented by a class in the managed environment, the .NET Framework supplies implementations of the COM interfaces listed in the following table on behalf of the object. A .NET class can override the default behavior by providing its own implementation of these interfaces. However, the runtime always provides the implementation for the IUnknown and IDispatch interfaces.
Interface Description
Idispatch
Provides a mechanism for late binding to type.
IerrorInfo
Provides a textual description of the error, its source, a Help file, Help context, and the GUID of the interface that defined the error (always GUID_NULL for .NET classes).
IprovideClassInfo
Enables COM clients to gain access to the ITypeInfo interface implemented by a managed class.
IsupportErrorInfo
Enables a COM client to determine whether the managed object supports the IErrorInfo interface. If so, enables the client to obtain a pointer to the latest exception object. All managed types support the IErrorInfo interface.
ItypeInfo
Provides type information for a class that is exactly the same as the type information produced by Tlbexp.exe.
Iunknown
Provides the standard implementation of the IUnknown interface with which the COM client manages the lifetime of the CCW and provides type coercion.
We are in the process of upgrading some VB6 code to .Net Specifically, we are re-writing some class definitions in the .Net environment to still be used in VB6. I think we have most of the stumbling blocks figured out, however, there is one design requirement due to poor programming that we need to implement. This requirement is to be able to have access to all child properties from its parent. Let's do a simple example that may illustrate this.
VB.Net Code
Public Class myBaseClass
Public myBaseClassProp As String
End Class
Public Class myDerivedClass
Inherits myBaseClass
Public myDerivedClassProp As String
End Class
From within VB6 I need to be able to access myBaseClss.myDerivedClassProp through code like
Dim md As New myDerivedClass
Dim mb as myBaseClass
Set mb=md
mb.myDerivedClassProp="test"
I did find the following blurb from the below website to slightly lead me in the right direction. However, it didn't give any examples or indications of actually how to go about doing this. I know if I can somehow override the Interfaces below, we can write our own implementation and use Reflections to get the property that we are looking for. I would also like to be able to do a mixture of early and late binding(which I don't know if it is possible) where all the regular properties are made available through intellisense and so that the application performs best.
The website/blurb is as follows:
http://msdn.microsoft.com/en-us/library/111chfb8(VS.80).aspx
In addition to exposing the interfaces that are explicitly implemented by a class in the managed environment, the .NET Framework supplies implementations of the COM interfaces listed in the following table on behalf of the object. A .NET class can override the default behavior by providing its own implementation of these interfaces. However, the runtime always provides the implementation for the IUnknown and IDispatch interfaces.
Interface Description
Idispatch
Provides a mechanism for late binding to type.
IerrorInfo
Provides a textual description of the error, its source, a Help file, Help context, and the GUID of the interface that defined the error (always GUID_NULL for .NET classes).
IprovideClassInfo
Enables COM clients to gain access to the ITypeInfo interface implemented by a managed class.
IsupportErrorInfo
Enables a COM client to determine whether the managed object supports the IErrorInfo interface. If so, enables the client to obtain a pointer to the latest exception object. All managed types support the IErrorInfo interface.
ItypeInfo
Provides type information for a class that is exactly the same as the type information produced by Tlbexp.exe.
Iunknown
Provides the standard implementation of the IUnknown interface with which the COM client manages the lifetime of the CCW and provides type coercion.