Click to See Complete Forum and Search --> : Persisting runtime properties


sidprice
June 13th, 2000, 12:50 PM
I would appreciate some advice and/or pointers to sample code for persisting runtime properties of ActiveX components designed with VB.

Thanks
Sid

Sid Price's Software Tools
http://www.softtools.com/tools/

Alec Ruderman
June 13th, 2000, 01:40 PM
option Explicit

Dim m_myprop as string

public property get MyProp() as string
MyProp = m_myprop
End property

public property let MyProp(byval NewValue as string)
m_myprop = NewValue
PropertyChanged "MyProp"
End property

private Sub UserControl_ReadProperties(byref Propbag as PropertyBag)
m_myprop = Propbag.ReadProperty("MyProp", "Default")
End Sub

private Sub UserControl_WriteProperties(byref Propbag as PropertyBag)
Call Propbag.WriteProperty("MyProp", m_myprop, "Default")
End Sub




The Above is an example of how to create a property and persist it's value. You must be sure and call the PropertyChanged Method to alert the user control that a property has changed and that it needs to be written into the Propbag otherwise it will not persist between design-time and run-time.

Hope this helps. Email me if you need more assistance.

Alec Ruderman
Alec_C_Ruderman@keane.com

sidprice
June 13th, 2000, 02:24 PM
Alec,

Thanks for the response. However, I believe that the code you gave persists the property at design time only. If I am mistaken please excuse me.

Sid

Sid Price's Software Tools
http://www.softtools.com/tools/

Chris Eastwood
June 13th, 2000, 02:35 PM
There are several ways of persisting data at runtime, including :

1. Using the registry (see the VB Help for GetSetting and SaveSetting for 'easy' registry access) - you can utilize the whole registry using code found on the CodeGuru site or any other big VB site.

2. Saving data to files using 'Open xxx for output...' etc - check in the on-line help

3. Saving / Restoring Data using XML (see the Microsoft site at http://msdn.microsoft.com/xml)

4. Using the new 'persistable' classes in VB6 - these give you access to a property bag object at runtime and can be used in a similar way to usercontrols for reading / writing data

Investigating the above will give you lots of ideas.


Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb