|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
You can also let the Package and Deployment Wizard (see Chapter 30) register the DLL file when its installed. Creating And Registering An Out-Of-Process Code ComponentHow do you create and register the real code component for use in actual client applications? There are two ways to create the actual code component: one if youre creating an in-process code component (an ActiveX DLL), and one if youre creating an out-of-process code component (an ActiveX EXE). We took a look at in-process code components in the previous topic, and well look at out-of-process code components here. To create the out-of-process code components EXE file, select the Make ProjectName.exe item in the Visual Basic File menu. How do you register that out-of-process code component with Windows? You just run the EXE filethats all it takes. You code component is now ready to use. Using The Class Initialize EventThe Initialize event occurs when a client application creates an instance of a class, and you can use this event to initialize the object thats being created. No arguments are passed to this events handler. Heres an example. When we created the class ExampleClass in the NewClass code component earlier in this chapter, we set up a property named NewValue and initialized it to 1 in the Initialize event handler like this:
Option Explicit
Public NewValue As Single
Private Sub Class_Initialize()
NewValue = 1
End Sub
Using The Class Terminate EventAn objects Terminate event occurs when the object goes out of scope, or when you set it to the Nothing keyword (see Destroying A Code Component Object later in this chapter). You can use this event to clean up after the object, such as releasing allocated memory or resources. Heres an example that you can add to the class ExampleClass in the NewClass code component developed earlier in this chapter. In this case, well use the Terminate event to display a message box to the users indicating that the ExampleClass object theyve created is being terminated:
Private Sub Class_Terminate()
MsgBox "Terminating now!"
End Sub
Global Objects: Using Code Components Without Creating An ObjectSometimes its difficult to create objects from code components in client applications, because the client application doesnt support coding to let you do so. To handle such cases, Visual Basic supports GlobalMultiUse code components. After adding one of these code components to a client application, you dont need to create an object before using its properties and methods. Properties and methods of a GlobalMultiUse object (or global object) are added to the global name space of any project that uses the object. In the client application, then, you can add a reference to the component, and the names of the global objects properties and methods will be recognized globally. You make a code component a GlobalMultiUse object with the Instancing property. The Instancing property indicates how you want your class to interact with client applications, if at all; here are the possible values of that property:
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |