Re: PropertyBag and settings




I see what you mean. You're suggesting to use
the UDT as property storage to write to disk.
That's fine. Or I could use an INI file like I've
been using. That works well. But what I liked
about this PropertyBag method is that I can
essentially save a class to disk. I use a PropertyBag
with a single property, and to that property I assign
the class itself. The PropertyBag.Contents is then
a byte stream, reflecting the state of the class,
which gets written to a file. So it's easy to populate
the class on load. VB does it for me. I just read in
the byte stream, assign it to the Contents of anoyher
PropertyBag, then "read" the single property into a
class object variable. Then I can pass that class to the
main EXE and it won't need to have any settings
variables of its own. It can just work straight out of the
class.

For instance, if I used to save a text color
in the Registry or in an INI file, I'd need to retrieve
it at startup, store it in a variable, and then do
something like:
Ob.SelColor = TColor
With the PropertyBag approach I can save all of the
settings as a class "snapshot" that gets loaded again
on next run. So there's no retrieval work and no
variables. I can just do:
Ob.SelColor = ClassSettings.TColor

And when someone changes settings I can just set
my class to nothing and get a new copy.

I had hoped that I could take a snapshot of the whole
class using this method, just capturing the memory
it inhabits, but it turns out that it can't work that
way. If I don't use the Class_ReadProperties and
Class_WriteProperties subs, as well as using PropertyChanged
when a property is changed, then the values don't
get written to disk. So it seems like this method should
work well but if I have, say, 50 program settings then it's
rather verbose. I'll need 100 Properties ( Get/Let * 50)
plus very long Class_ReadProperties and
Class_WriteProperties subs. I'm thinking that I might try
to somehow use some arrays to store multiple values.
I don't know yet whether the PropertyBag can handle that.


What were you doing with the Property Bag?

Private Type UserSettings
A as long
B as Long
.. etc...
End Type

Dim us as UserSettings

Sub Form_Load()
SF = Freefile
Open SettingsFile for binary as SF
Get SF, , us
Close SF
End Sub


The write operation is the same except for Put where
Get is. I can't imagine how that could get ugly.
The ONLY hard part is deciding where the settings
file needs to go.....

LFS




.



Relevant Pages

  • Re: PropertyBag and settings
    ... the UDT as property storage to write to disk. ... Or I could use an INI file like I've ... With the PropertyBag approach I can save all of the ... ' Erases all settings ex: ...
    (microsoft.public.vb.general.discussion)
  • Re: Power failure
    ... There is no option named "make startup disk". ... I think it should be no problem at all to make that emergency boot CD from my system... ... cmos/bios settings. ... Further they re-installed her hard disk last August and the store gave CD's as well for system restore. ...
    (microsoft.public.windowsxp.general)
  • Re: Slow performance
    ... I realize that the pagefile usage is excessive and I need to reduce memory ... I've never messed with those settings before. ... Peak are greatly in excess of the installed RAM. ... The Disk Defragmenter report shows you have minimal free disk space. ...
    (microsoft.public.windowsxp.perform_maintain)
  • RE: I hope someone can help....CD-RW not seeing anything
    ... "boot from disk". ... I checked my BIOS settings, ... > Device Manager shows the correct drive info and it says the devise is working ... > there are other programs and software updates not installing correctly. ...
    (microsoft.public.windowsxp.general)
  • RE: I hope someone can help....CD-RW not seeing anything
    ... I logged in on a different administrator profile, ... > "boot from disk". ... I checked my BIOS settings, ... >> to uninstall the devise and restart, now it shows the drive to be only CD ROM ...
    (microsoft.public.windowsxp.general)

Quantcast