PDA

Click to See Complete Forum and Search --> : ReadProperties purpose


john_tse
May 16th, 2009, 05:20 PM
Hello, im a newbie in this world of OCX programming and i still cant understand whats the purpose of the ReadProperties event and whats the difference between this:

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
TextVariable = PropBag.ReadProperty("Text", "There is no message")
End Sub

and this:

Public Property Get Text() As String
Text = TextVariable
End Property

The ReadProperties event is activated when i read any property or only when i read a particular one?

I think im lost :).

I hope you can help me.

Kind regards.

LaVolpe
Jun 10th, 2009, 08:54 AM
The ReadProperties event occurs every time a usercontrol in your project has just been created and is first sited on the host container. The InitiProperties event occurs only once and it occurs the very first time the control is dragged onto the container from your toolbox; after that, ReadProperties is called. ReadProperties only occurs once, not for every property. You are expected to retrieve all stored properties and cache them in your code.

ReadProperties allows you to retrieve previously stored properties that were written in the WriteProperties event. WriteProperties occurs only in design view and what you are writing is basically the properties you exposed as Public that also appear on the property sheet. You can also write custom/internal/personal values if needed. This event only occurs when the control is about to be destroyed (i.e., form closing)

But I can go on and on regarding the properties and events of usercontrols. Let me give you an excellent link that will help (http://pntpm3.ulb.ac.be/Info/Activex/). Specifically, look at Chapter 17.