Re: PropertyBag and settings
- From: "mayayana" <mayayaXXna@xxxxxxxxx>
- Date: Sat, 21 Feb 2009 23:26:54 -0500
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
.
- Follow-Ups:
- Re: PropertyBag and settings
- From: Larry Serflaten
- Re: PropertyBag and settings
- References:
- PropertyBag and settings
- From: mayayana
- Re: PropertyBag and settings
- From: Larry Serflaten
- Re: PropertyBag and settings
- From: mayayana
- Re: PropertyBag and settings
- From: Larry Serflaten
- PropertyBag and settings
- Prev by Date: Re: Visual Basic 6.0 has added support for HTML Help files?
- Next by Date: Re: Test (yeah, I know)
- Previous by thread: Re: PropertyBag and settings
- Next by thread: Re: PropertyBag and settings
- Index(es):
Relevant Pages
|