Home
  ASP
  VB
  PHP
  Contact Us

 


Partners
Visual Basic News & Information Source


       

Persistable COM (Using MSMQ)

I wont go into the details of using MSMQ, you can figure out yourself by looking at the code but the important thing is how we used the property bag to store the information and then later retrieve that information from the property bag to send via MSMQ.

Just look at the code of the class how we made the component persistable by storing the information in the property bags. A property bag object holds information that is to be saved and restored across invocations of an object.

A property bag object is passed into an object through the readproperties event and the writeproperties event in order to save and restore the state of the object. Using the methods of the property bag object, the object can read or write properties of itself. The readproperty method of the propertybag is used to read a value for a property, while the writeproperty method of the propertybag object is used to write a value of a property. The value of a property can itself be an object; in that case the propertybag object will attempt to save it.

Also, the code will show you how to use the MSMQ to pass a persistable component to the MSMQ Server.

Wish you all the best.

CLASS CODE:

Option Explicit

Private mstrFirstName As String
Private mstrLastName As String

Public Property Get LastName() As String
LastName = mstrLastName
End Property

Public Property Let LastName(strNewName As String)
mstrLastName = strNewName
End Property

Public Property Get FirstName() As String
FirstName = mstrFirstName
End Property

Public Property Let FirstName(strNewName As String)
mstrFirstName = strNewName
End Property



Private Sub Class_ReadProperties(PropBag As PropertyBag)
mstrLastName = PropBag.ReadProperty("LastName")
mstrFirstName = PropBag.ReadProperty("FirstName")
End Sub

Private Sub Class_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "LastName", mstrLastName
PropBag.WriteProperty "FirstName", mstrFirstName
End Sub

FORM CODE:

Private Sub Command1_Click()
Dim objPersist As PersistableCOM.PCOM
Dim objQueueInfo As MSMQQueueInfo
Dim objQueue As MSMQQueue
Dim objMessage As MSMQMessage

On Error GoTo Command1_ClickErr

'Add some state to the instance of PCOM class
Set objPersist = New PersistableCOM.PCOM
objPersist.FirstName = txtSendFN.Text
objPersist.LastName = txtSendLN.Text

'Get a reference to the Queue
Set objQueueInfo = New MSMQ.MSMQQueueInfo
objQueueInfo.PathName = ".\testq"

Set objQueue = objQueueInfo.Open(MQ_SEND_ACCESS, _
				MQ_DENY_NONE)

'Build the message
Set objMessage = New MSMQ.MSMQMessage
objMessage.Label = "PCOM Object"
objMessage.Body = objPersist
objMessage.Send objQueue

'Close the queue
objQueue.Close

Exit_handler:

Set objMessage = Nothing
Set objQueue = Nothing
Set objQueueInfo = Nothing
Exit Sub

Command1_ClickErr:

MsgBox "Error... " & Err.Description, vbCritical, Err.Source & _
			" (" & Err.Number & ")"
Resume Exit_handler

End Sub

Private Sub Form_Load()

End Sub

 

    


 


 

Home | ASP | VB | PHP | Contact Us


© 2002 Wali Systems Inc.