![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
Click on the OK button to close the Project Properties dialog box. Next, use the Properties window to set the class properties. Only two of the properties concern us for this project; the settings and an explanation of each follow:
Once the class modules properties are set, we can add the declarations of the variables that will be the classs properties. You accomplish this in the General Declarations section of the class module. Heres the code: Option Explicit Private pObjName As Variant Private pDateCreated As Date Private pNumber As Double Private pSquareRoot As Double Private pCubeRoot As Double The Option Explicit statement should already be present, placed there automatically by Visual Basic. If not, you need to select Options from the Tools menu; on the Editor tab, turn on the Require Variable Declarations option. Lacking the Option Explicit statement in a module, Visual Basic does not require variables to be declareda definite invitation to errors. If you examine these variable declarations, youll see that all of them are Private, meaning they are not accessible outside the ActiveX server. They can be used for purely internal uses by the class, or they can be exposed to clients as properties (for reading, writing, or both) by means of property procedures. When you expose a variable with a property procedure, it becomes one of the objects properties that can be accessed by clients. We need to take a short detour from the demonstration project to explore property procedures. First, however, save the project. I used the default names suggested by Visual Basic: MyTestAXDLL for the project and AXDEMO for the class module (class modules are automatically given the .CLS extension). Property ProceduresYou had an introduction to property procedures in Chapter 6; now the time has come to learn more. Property procedures are a central part of ActiveX server programming. While you may be able to create very simple servers without using property procedures, youll find them essential for most of your projects. You can use a property procedure to create standard read/write properties that can be both read and set by clients. These procedures also permit you to create read-only properties, perform some action when the property is read or set, or assign a Help topic to the property. Property procedures come in three varieties. Property Get and Property Let are usually used in tandem, permitting the client to read and set, respectively, the value of a property in the ActiveX object. Property Set is used in place of Property Let when the property in question contains a reference to an object. Because the demonstration server does not use object reference properties, Ill limit the discussion to Property Get and Property Let. Lets assume we want the object to hav |