NET components can not be used in straight forward way with COM. You will need to create CCW (COM Callable Wrapper) in order that COM components communicate with .NET assemblies. Following are the different approaches to implement it:
§ Explicitly declare interfaces.
Public Interface ICustomer
Property CustomerName() As String
Property CustomerCode() As String
Sub AddCustomer()
End Interface
Public Class Customer Implements ICustomer
Private PstrCustomerName As String
Private PstrCustomerCode As String
Public Sub AddCustomer() Implements ICustomer.AddCustomer
Try
‘ addin of database code can go here
Catch ex As Exception
Throw ex
End Try
End Sub
Public Property CustomerCode() As String Implements
ICustomer.CustomerCode
Get
Return PstrCustomerCode
End Get
Set(ByVal value As String)
PstrCustomerCode = value
End Set
End Property
Public Property CustomerName() As String Implements
ICustomer.CustomerName
Get
Return PstrCustomerName
End Get
Set(ByVal value As String)
PstrCustomerName = value
End Set
End Property
Public Sub New()
End Sub
End Class
The above customer class is going to be used by COM components so all the properties and methods are declared in interface and implemented in the customer class. Customer Name.Customer Code and AddCustomer are first declared in ICustomer and then implemented in Customer Class. Also note that the class must have a default constructorProperty CustomerName() As String
Property CustomerCode() As String
Sub AddCustomer()
End Interface
Public Class Customer Implements ICustomer
Private PstrCustomerName As String
Private PstrCustomerCode As String
Public Sub AddCustomer() Implements ICustomer.AddCustomer
Try
‘ addin of database code can go here
Catch ex As Exception
Throw ex
End Try
End Sub
Public Property CustomerCode() As String Implements
ICustomer.CustomerCode
Get
Return PstrCustomerCode
End Get
Set(ByVal value As String)
PstrCustomerCode = value
End Set
End Property
Public Property CustomerName() As String Implements
ICustomer.CustomerName
Get
Return PstrCustomerName
End Get
Set(ByVal value As String)
PstrCustomerName = value
End Set
End Property
Public Sub New()
End Sub
End Class
No comments:
Post a Comment