VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering

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

Implementing Property Persistence

You can keep information about properties whose values you want to make persistent in the Property Bag object of the UserControl. The Property Bag object has two methods you will call: ReadProperty (to retrieve a property's value from the Property Bag) and WriteProperty (to store a property's value in the Property Bag).

In addition, you can maintain properties as you would in any ActiveX Class module: by writing and reading the Private variables that are used to store the property values between calls to Property procedures.

On the other hand, if you've chosen to implement properties with Public variables, you can also manipulate and monitor these properties by reading and writing the Public variables.

You can use these techniques to initialize and maintain persistent property values in your UserControl.

Here is a list of the events you need to know about to maintain properties. For each event listed, we tell when the event occurs and give a brief note about how you would use the event's procedure to maintain persistent property values. We provide more detailed information on the Property Bag and on these events in the following sections.

  • The InitProperties event happens only once in the lifetime of a custom control's instance: when the developer actually creates a new instance of the control by clicking on the control's toolbox icon and placing the new instance in a container. Use the InitProperties event to set default initial values for your custom properties and for properties provided by the Extender object.

  • The Initialize event is essentially the same as the Initialize event of any Class module. It happens as the instance of the UserControl is about to be created.

  • The ReadProperties event happens whenever an instance of the control is created. If this is the first time the control has been created (i.e. the developer has used the toolbox to place a copy of the control on the form), then ReadProperties happens after InitProperties. You can put code in the ReadProperties event procedure to retrieve saved persistent property values.

  • The WriteProperties event happens whenever an instance of the control is destroyed and at least one property has been changed (you can notify the system that a property has been changed by calling the PropertyChange method of the UserControl). You can put code in the WriteProperties event procedure to save property values that you would like to persist.

  • The Terminate event is essentially the same as the Terminate event of any Class module. It happens as the instance of the UserControl is about to be destroyed.

  1. Using the InitProperties Event to Set Default Starting Property Values
  2. The InitProperties Event Versus the Initialize Event
  3. Using the Property Bag to Store Property Values
  4. Using ReadProperties and WriteProperties Events and Corresponding Methods to Maintain Persistent Properties
  5. Storing Persistent Property Values with the WriteProperties Event and the WriteProperty Method
  6. Calling the PropertyChanged Method to Trigger WriteProperties
  7. Retrieving Persistent Property Values with the ReadProperties Event and the ReadProperty Method


<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved