Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering


You are here: Visual Basic > Advanced VB6 tutorial > Chapter 12

Implementing the Callback Object in the Client

When you are programming a client application and want to use the callback functionality that an Interface provides, you must take the following steps outlined in Step by Step 12.6 to use a callback object in your application.

STEP BY STEP
12.6 Implementing a Callback Object in the Client

  1. Add a class to the client application and name it appropriately.

  2. Make sure that the Instancing property of the new class is Private. (If the client project is not an ActiveX EXE or ActiveX DLL, the Class Instancing property will not be available to you, and Instancing will be Private by default.)

  3. Implement the server's callback Interface in this class (see Listing 12.22). Put appropriate notification code in the callback's notification method.

  4. Instantiate copies of the callback object (should be Public variables) and call the appropriate methods of the server class objects that will receive instances of the callback object as parameters (see Listing 12.22).

Listing 12.22 gives the code in the class module that you would add to the client. As mentioned in step 3, this Client class implements the server's Interface class, INotification, which was discussed in the section titled "Providing an Interface for the Callback Object." Because INotification has only one member, the Notify method, you need only to write code to implement that method. The Notify method will be called from inside the server to send a notification back to this client. Because this client implements the Notify method, it can therefore specify the exact way in which it will be notified.

Recall from the preceding section that the Interface for INotification specifies that the Notify method will accept one String parameter, so you must implement the String parameter here.

LISTING 12.22
IMPLEMENTING THE INTERFACE FOR A CALLBACK IN A Client CLASS

'Class Name = CallBack
Option Explicit
Implements INotification
Private Sub Inotificatiion_Notify(msg As String)
MsgBox msg
'or do something else with msg
End Sub

In Listing 12.23, the client code instantiates a server class object, instantiates an object from the callback class that you defined in Listing 12.22, and then passes the resulting callback object to the server object's LongProcess method.

LISTING 12.23
PASSING A Callback OBJECT TO A SERVER OBJECT

Public objServer As New MyServer.MyClass
Public cbCurrent As CallBack
.
.
Set cbCurrent = New CallBack
objServer.LongProces cbCurrent

The server's LongProcess method is specifically designed to accept an object that's been instantiated from a class that implements the INotification Interface (see the section titled "Manipulating the Callback Object in the Server"). After the server has received the object, it may at some point call the object's Notify method— which you have implemented in the client to provide a client-side notification.


  

<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved