Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Global Property Bag, is it Prossible?

13 views
Skip to first unread message

Eduardo

unread,
Oct 5, 2008, 5:58:12 AM10/5/08
to
Is it Possible, within an ActiveX Project, to have a global property bag
that can write and read values from a class module or a bas module at any
time?


Ralph

unread,
Oct 5, 2008, 7:07:47 AM10/5/08
to

"Eduardo" <m...@mm.com> wrote in message news:gca5m0$hrp$1...@aioe.org...

> Is it Possible, within an ActiveX Project, to have a global property bag
> that can write and read values from a class module or a bas module at any
> time?
>

A Property Bag is a storage device which holds Variants. You can easily make
one globally available by simply declaring one globally.

http://gpwiki.org/index.php/VB:Property_Bag_Resource_File

-ralph


Eduardo

unread,
Oct 5, 2008, 12:51:27 PM10/5/08
to
Hello and thanks,

Well, I see that in the sample the author stores the property bag Contents
in a custom file.
I wonder if at runtime this file is also needed or if the property bag
Contents can be stored instead on the exe file, as VB does with its built in
property bags.

Because if one needs to use also a custom file when the client project is
compiled, then there is no advantage in using a property bag.

What I'm looking for is precisely that: to be able to store some data in the
exe that can be be read by my ocx.

At design time, I could manage to store the data anywhere, but the key point
is how to send this data with the compiled program without adding any
auxiliary file?

"Ralph" <nt_cons...@yahoo.com> escribió en el mensaje
news:elEnStt...@TK2MSFTNGP04.phx.gbl...

Eduardo

unread,
Oct 5, 2008, 2:43:42 PM10/5/08
to
Well, I made a test program and as I supposed, the property bag Content
isn't stored anywere at compilation.

So I changed the subject to "Store data into the exe at compile time".

The question then is: how to store some data into the exe at compile time,
as an Usercontrol's property bag does?

And I'll explain a bit why I need that.
I'll give an example:

Supose that I have created an Usercontrol that in one of its properties
stores a list of images.
But I want all the instances of my Usercontrol to share the same list of
images. So when the programmer places another instance of my control in a
form, it already has the images loaded in that property (because a previous
instance of the control loaded the images already).
I can do that by keeping that data in a array of stdPictures in a bas
module.

But the problem comes when I have to store that images.
At design time, I can store them in a custom file saved somewhere. But, how
to carry that images with the client's compiled exe?

VB does that for every control, it stores the additional data in a .frx file
at design time for every form that needs it (i can do the same with a custom
file), but when compiled it doesn't carry the .frx files, it stores the data
into the exe.

The first thing one thinks, is to store it in one of the Usercontrol's
instances property bags... but wich one? How do I know what is the first
form that will be loaded in the client program? Impossible.

So, as I need to load this data when the fist instance of my usercontrol
loads, and I don't know what instance is going to be loaded first, so the
only thing I can do is to strore the data (the same data) for all and every
instance of my control.

Suppose that the list of images is a list of 5 files of 200 Kb each one. I
have 1 MB of data that will be stored in the exe. That's OK. But... that's
OK if it's stored only one time. But if the programmer added my control in 5
forms, it will be 5 MB of data, all repeating the 1 MB 5 times, and that's
not OK.

Is the situation clear?

Thanks.


"Eduardo" <m...@mm.com> escribió en el mensaje news:gcarhe$gb6$1...@aioe.org...

Ralph

unread,
Oct 5, 2008, 3:25:36 PM10/5/08
to

"Eduardo" <m...@mm.com> wrote in message news:gcarhe$gb6$1...@aioe.org...

> Hello and thanks,
>
> Well, I see that in the sample the author stores the property bag Contents
> in a custom file.
> I wonder if at runtime this file is also needed or if the property bag
> Contents can be stored instead on the exe file, as VB does with its built
in
> property bags.
>
> Because if one needs to use also a custom file when the client project is
> compiled, then there is no advantage in using a property bag.
>
> What I'm looking for is precisely that: to be able to store some data in
the
> exe that can be be read by my ocx.
>
> At design time, I could manage to store the data anywhere, but the key
point
> is how to send this data with the compiled program without adding any
> auxiliary file?
>

At design-time one of the "features" of VB's control creation is the ability
to store property information in the Data segment (tags) and in a Resources
(values, objects, etc). However, even this information is read/write only at
runtime. Controls that need to preserve data usually use the Registry.

[Note: Property Bags store data as a single binary 'string'.]

Schemes that write to an Exe, which could be easily done by appending a file
to end of an Exe (or OCX, DLL, ...), unfortunately often run afoul of a
Virus Checker or have permissions issues. The latter is especially a problem
with Vista.

Frankly, using an external storage - whether Registry (for small quanities),
INI, or file is a best practice. Especially when you consider Vista's
tightened permissions, possible user or machine specific data (profiles),
security, the fact it is flexible, and just plain simple.

[Note: For VB6 questions beyond 'creating controls' you should post to
"microsoft.public.vb.general.discussion". More VB6 programmers hang out
there.]

hth
-ralph


Ralph

unread,
Oct 5, 2008, 3:44:50 PM10/5/08
to

"Eduardo" <m...@mm.com> wrote in message news:gcb1t8$bj0$1...@aioe.org...

For some reason I did not see this post when I posted my other response. The
other post implied you were looking for the ability to preserve read/write
data. However, if you only need to store static data you have other
options... Once again you could store those images in an external file and
load them by using the .Contents method of a Property Bag.

However, an .frx file is actually nothing other than a Resource File, or
rather a semi-compiled resource. which when you compile your program are
combined into a single Resource and attached to your executable. You could
do the same.

This should get you started...
http://www.thevbzone.com/l_res.htm

Again for this subject, I feel you will get more responses (and review of
those responses) if you post to "microsoft.public.general.discussion".

hth
-ralph


Eduardo

unread,
Oct 5, 2008, 4:02:50 PM10/5/08
to
Ralph,

I can't use the registry because I need to preserve data between design time
and compiled time.

Appeding data to the exe is an idea, but how can my ocx know that an exe was
generated and so append the data? And also it has the drawbacks that you
mention: Vista, firewalls, etc.

Another idea that I have, is to store the data in the first instance of my
control that writes properties, and store it as a custom property. So I
could place a string to use it as the key, for example "here is what you are
looking for" and after that all the data. And then at compiled time, the
first instance of the control that loads, in the ReadProperties event opens
the exe and search for that key string, and then reads all the following
data that is the data that is needed to load.

This also has the drawback that could have problems with Vista and
firewalls, but I'm not sure (because I only open the file for read).
Another drawback of it, is that if the exe is a big one, say 20 MB, it could
take a while until it finds the key.

"Ralph" <nt_cons...@yahoo.com> escribió en el mensaje

news:eTvrdDyJ...@TK2MSFTNGP06.phx.gbl...

Eduardo

unread,
Oct 5, 2008, 4:14:54 PM10/5/08
to
Ralph,

> Again for this subject, I feel you will get more responses (and review of
> those responses) if you post to "microsoft.public.general.discussion".

It's all about control creation.
I could post there, but I'll need to explain more to people that are not
familiar with ActiveX controls.

I think, will all respect, that you still didn't get the point of what I'm
talking about.

I cannot use a resource file. In any case, the programmer of the client
program could use one. But it will make the use of my control much, much
harder. To set as a requirement that they have to use a resorce file to
store my control data, it is inadmissible. My control have to work easy, it
have to manage for itseld its own "problems" and not to put load to the
programmer shoulders.

But the point about resource files is: could I append data to the resource
data section of the exe at compilation time? (compilation of the client
project, when the client is compiling his exe - the only .exe here because
mine is .ocx-).

May be you would like to re-read my previous post, the one that you are
answering here, because I explained there the situation quite clearly (i
believe).

Thanks.

"Ralph" <nt_cons...@yahoo.com> escribió en el mensaje
news:OpMaaOyJ...@TK2MSFTNGP06.phx.gbl...

Ralph

unread,
Oct 5, 2008, 4:41:01 PM10/5/08
to

"Eduardo" <m...@mm.com> wrote in message news:gcb787$43q$1...@aioe.org...

> Ralph,
>
> > Again for this subject, I feel you will get more responses (and review
of
> > those responses) if you post to "microsoft.public.general.discussion".
>
> It's all about control creation.
> I could post there, but I'll need to explain more to people that are not
> familiar with ActiveX controls.
>
> I think, will all respect, that you still didn't get the point of what I'm
> talking about.
>

Obviously, you are correct, I don't. Your posts are coming across as
multi-variant musings. I have no doubt it is all crystal clear to you, but
it is quite illusive to me. But then I've only been programming for 30
years.

Again, I suggest you post to "microsoft.public.general.discussion". I assure
you your assumptions about who frequents that newsgroup are in error. Your
posts need to be presented to as wide an audience as possible.

-ralph


Schmidt

unread,
Oct 5, 2008, 6:48:56 PM10/5/08
to

"Eduardo" <m...@mm.com> schrieb im Newsbeitrag news:gcb787$43q$1...@aioe.org...

> > Again for this subject, I feel you will get more responses
> > (and review of those responses) if you post to
> > "microsoft.public.general.discussion".
>
> It's all about control creation.
> I could post there, but I'll need to explain more to people
> that are not familiar with ActiveX controls.

Trust me, Ralph was right - if you'd have posted there, you'd
already got your answer - anyway will try to put my 2cents
in here... ;-)

Since you're already aware, that a *.bas-module in your
Ctl-Project will be shared among your Ctl-Instances, you
should make use of that fact.
Simplest way to achieve what you want is the following:


'***Into a UserCtl-Project (Projectname=PicTest,
'***CtlName=PTest) and place an array of VBs-
'***ImageControl-Type on it named: ImageArr
Option Explicit

Public Function GetImageResource(KeyOrIndex)
Set GetImageResource = glbImageCollection(KeyOrIndex)
End Function

Private Sub UserControl_Initialize()
Dim i&
If glbImageCollection.Count = 0 Then 'we do this only once
For i = 0 To ImageArr.UBound
glbImageCollection.Add ImageArr(i).Picture, "ImageKey" & i + 1
Next i
End If

'since we already placed the Img-resources globally, we can
'delete now from the Img-Resource-Holders (our VB-ImageCtl-Arr)
For i = 0 To ImageArr.UBound
Set ImageArr(i).Picture = Nothing
ImageArr(i).Visible = False
Next i
End Sub

'***in the same UserCtl-Project place a module with the following:
Option Explicit

Public glbImageCollection As New Collection
'-----------------------------------------------------

That's all for our small UserCtl-Project, now place appropriate
Picture-Content in the members of the ImageArr and compile.

To test that it works, place the following in a new Std-Exe-
Project:
'***Into a Form
Option Explicit

Private Sub Form_Load()
Dim i&
Me.WindowState = vbMaximized
Me.ScaleMode = vbPixels
Me.Show
For i = 0 To 19 'add 20 Ctl-Instances
With Controls.Add("PicTest.PTest", "MyCtlKey" & i)
.Move 100, i * 20 + i * 2, 100, 20
.Visible = True
End With
Next i

'just to demonstrate, that your Public "resource-function"
'works as supposed
Set Me.Picture = Controls("MyCtlKey0").object.GetImageResource(1)
End Sub

Now compile that and check yourself in the taskmanager,
if this Std-Exe uses 20 x the amount of your Image-Content
or only once (though hosting 20 instances of your Test-UserCtl).

Olaf


Eduardo

unread,
Oct 5, 2008, 8:34:14 PM10/5/08
to

"Ralph" <nt_cons...@yahoo.com> escribió en el mensaje
news:ePygmtyJ...@TK2MSFTNGP06.phx.gbl...

>
> "Eduardo" <m...@mm.com> wrote in message news:gcb787$43q$1...@aioe.org...
>> Ralph,
>>
>> > Again for this subject, I feel you will get more responses (and review
> of
>> > those responses) if you post to "microsoft.public.general.discussion".
>>
>> It's all about control creation.
>> I could post there, but I'll need to explain more to people that are not
>> familiar with ActiveX controls.
>>
>> I think, will all respect, that you still didn't get the point of what
>> I'm
>> talking about.
>>
>
> Obviously, you are correct, I don't. Your posts are coming across as
> multi-variant musings. I have no doubt it is all crystal clear to you, but
> it is quite illusive to me. But then I've only been programming for 30
> years.

It could mean that I don't explain well, or that the subject is very
unusual, or both.


> Again, I suggest you post to "microsoft.public.general.discussion". I
> assure
> you your assumptions about who frequents that newsgroup are in error. Your
> posts need to be presented to as wide an audience as possible.

OK, Thanks.

>
> -ralph
>
>

Eduardo

unread,
Oct 5, 2008, 8:29:03 PM10/5/08
to
Schmidt,

In your sample the images are fixed within the Usercontrol, but in my case
they will be added by the programmer at design time (any image).
The case is very different.
Thank you anyway.

> Trust me, Ralph was right - if you'd have posted there, you'd
> already got your answer - anyway will try to put my 2cents
> in here... ;-)

OK. Thanks.

"Schmidt" <s...@online.de> escribió en el mensaje
news:uaNacyzJ...@TK2MSFTNGP05.phx.gbl...

Schmidt

unread,
Oct 6, 2008, 10:07:25 AM10/6/08
to

"Eduardo" <m...@mm.com> schrieb im Newsbeitrag news:gcbmeu$289$1...@aioe.org...

> In your sample the images are fixed within the Usercontrol,
> but in my case they will be added by the programmer at
> design time (any image).
> The case is very different.

Ok, but even in this case I don't really see, where the
problem is.
If you are the provider of the compiled OCX, then you
are free, to include an additional Public Ctl into your OCX-
Project, which you could call ImgResManager if you
want - and in your customer-documentation is then
clearly statet, that your ImgResManager should only
be used on one single user-form in your customers project.

Then let this separate "Singleton-Control" act as the
global Res-Storage, which at runtime then provides
its stored "*.frx-PropBag-content" over an "OCX-
global *.bas-module" to your other (multi-instance)
control-types which were instantiated from the same
OCX.

Olaf


Eduardo

unread,
Oct 6, 2008, 1:27:41 PM10/6/08
to
"Schmidt" <s...@online.de> escribió en el mensaje
news:urzxrz7...@TK2MSFTNGP03.phx.gbl...

>
> "Eduardo" <m...@mm.com> schrieb im Newsbeitrag news:gcbmeu$289$1...@aioe.org...
>
>> In your sample the images are fixed within the Usercontrol,
>> but in my case they will be added by the programmer at
>> design time (any image).
>> The case is very different.
>
> Ok, but even in this case I don't really see, where the
> problem is.

In this case there is no problem.

> If you are the provider of the compiled OCX, then you
> are free, to include an additional Public Ctl into your OCX-
> Project, which you could call ImgResManager if you
> want - and in your customer-documentation is then
> clearly statet, that your ImgResManager should only
> be used on one single user-form in your customers project.

Yes, could be. And that it must be loaded with the first instance of the
other control.
That means that it must be placed on the first form that uses my other
control.

But I don't like this idea, because my control is very easy to use and
intuitive (now), and it is used for any sort of programmers, may be some of
then knows little more than making "hello worl" projects.

I could also have the resources managed by only one instance of my current
control (without adding another control type) and tell them that they must
indicate in a property wich one instance of the control that they added will
load in first place. But it is the same case: complication.

Of course there are things that can be done. I could say that they must have
the images in a Imagelist control and must send a reference of that
Imagelist to the first instance of my control that loads, etc. All
complications to my users that I don't want. No way.

Thank you.

Eduardo

unread,
Oct 6, 2008, 3:30:42 PM10/6/08
to
Well, to summarize some things that I made clean from this conversation:

Ralph said that all the resources of the forms that at design time are saved
in the *.frx files, when compiled they are stored in the exe _as resources_.

I suppose that VB has a way to distinguish between those rersources from the
resorces that the programmer adds with a resource file, but I suppose
(correct me if I'm wrong) that the resources that the programmer adds with
the resource file and the resources of the forms are all stored as resoruces
in the exe in the same way.

Then, I think I could use an API, may be LoadImage, to access that
resources.

No matter if the form (that contain the resources I need) has already been
loaded or not, I can access its
resources with API calls.

But then, how to identify in the list of resorces, where is the resource
that I need to load?

Any clue?

Thanks.

PS: I still didn't post to the other group.

"Eduardo" <m...@mm.com> escribió en el mensaje news:gca5m0$hrp$1...@aioe.org...

Eduardo

unread,
Oct 6, 2008, 3:51:32 PM10/6/08
to
It seems that my assumption that the form's resources are stored as normal
resources in the exe is wrong.

I run this sample:
http://allapi.mentalis.org/apilist/7ECF27320393EB56B2A2F1406BA51BC9.html

And if I add images with a resorce file added to the project, they appear in
the list of resources, but if I add images to an Imagelist control placed on
a form, they don't appear in the list.

"Eduardo" <m...@mm.com> escribió en el mensaje news:gcdp1b$n43$1...@aioe.org...

Schmidt

unread,
Oct 6, 2008, 4:07:21 PM10/6/08
to

"Eduardo" <m...@mm.com> schrieb im Newsbeitrag news:gcdi3l$81b$1...@aioe.org...

> "Schmidt" <s...@online.de> escribió en el mensaje
> news:urzxrz7...@TK2MSFTNGP03.phx.gbl...
> >
> > "Eduardo" <m...@mm.com> schrieb im Newsbeitrag
news:gcbmeu$289$1...@aioe.org...
> >
> >> In your sample the images are fixed within the Usercontrol,
> >> but in my case they will be added by the programmer at
> >> design time (any image).
> >> The case is very different.
> >
> > Ok, but even in this case I don't really see, where the
> > problem is.
>
> In this case there is no problem.
Then, why do you post at all? ;-)

> > If you are the provider of the compiled OCX, then you
> > are free, to include an additional Public Ctl into your OCX-
> > Project, which you could call ImgResManager if you
> > want - and in your customer-documentation is then
> > clearly statet, that your ImgResManager should only
> > be used on one single user-form in your customers project.
>
> Yes, could be. And that it must be loaded with the
> first instance of the other control.
> That means that it must be placed on the first form that
> uses my other control.

No, it has not to be placed on that form - it should be
placed on the Startup-Form of the project.

> Of course there are things that can be done.

Of course, maybe with PropertyPages or with your
own Ctl-UserDialog you can manage, to place the
resources in only one Ctl-Instance of the possible
multiple instances.

> I could say that they must have the images in a
> Imagelist control and must send a reference of that
> Imagelist to the first instance of my control that loads, etc.
> All complications to my users that I don't want. No way.

But somehow your users have to say to "some Image-
Resource-Handler-Instance" what they want.
And since the Imagelist-Ctl already offers nice Property-
Pages for that task (a not all that complicated GUI) ...
why not this way. You could even try to enumerate
the Forms from within your Controls on startup, to
find the matching (if you defined an appropriate Naming-
Convention in your Docu) ImageList automatically.

As you already said, many things, that can be done... ;-)

Olaf


Eduardo

unread,
Oct 6, 2008, 4:58:24 PM10/6/08
to
"Schmidt" <s...@online.de> escribió en el mensaje
news:u1Rlz8%23JJH...@TK2MSFTNGP03.phx.gbl...

>
> "Eduardo" <m...@mm.com> schrieb im Newsbeitrag news:gcdi3l$81b$1...@aioe.org...
>> "Schmidt" <s...@online.de> escribió en el mensaje
>> news:urzxrz7...@TK2MSFTNGP03.phx.gbl...
>> >
>> > "Eduardo" <m...@mm.com> schrieb im Newsbeitrag
> news:gcbmeu$289$1...@aioe.org...
>> >
>> >> In your sample the images are fixed within the Usercontrol,
>> >> but in my case they will be added by the programmer at
>> >> design time (any image).
>> >> The case is very different.
>> >
>> > Ok, but even in this case I don't really see, where the
>> > problem is.
>>
>> In this case there is no problem.
> Then, why do you post at all? ;-)

_Your_ example doesn't have the problem because it uses fixed resources.
They are stored in the ocx file at runtime and are always the same for every
programmer and every project that uses the ocx.

My case is different. You just eluded the key point in your example.

You are focusing in how the programmers will add the images, and I don't
care about that, that's not the problem.

>You could even try to enumerate
> the Forms from within your Controls on startup, to
> find the matching (if you defined an appropriate Naming-
> Convention in your Docu) ImageList automatically.

The forms collection (of the client program) only has the forms that are
loaded in that moment, but not all the forms that the host project has.

> As you already said, many things, that can be done... ;-)

Yes, I have confidence to find a way to do that without telling the
programmer to do anything in a particular way.
But I still don't know how.

When I develop, I stick to the idea that the users (programmers in this
case, but also users - of my control -) will do wrong things, horrible
things may be, and the program have to manage to work in the best possible
way without reling that the users are advanced, and read documentation, and
are smart.

>
> Olaf
>

Thanks.


Eduardo

unread,
Oct 6, 2008, 5:08:29 PM10/6/08
to
"Eduardo" <m...@mm.com> escribió en el mensaje news:gcdubc$qib$1...@aioe.org...

> "Schmidt" <s...@online.de> escribió en el mensaje

>>> I could say that they must have the images in a


>>> Imagelist control and must send a reference of that
>>> Imagelist to the first instance of my control that loads, etc.
>>> All complications to my users that I don't want. No way.
>> But somehow your users have to say to "some Image-
>> Resource-Handler-Instance" what they want.
>> And since the Imagelist-Ctl already offers nice Property-
>> Pages for that task (a not all that complicated GUI) ...
>> why not this way.
>
> You are focusing in how the programmers will add the images, and I don't
> care about that, that's not the problem.

To clarify:

I am focusing in how to store the images oly once (in the exe), and then
load them form any instance of my control. No matter if it's the same
control instance that saved them or not.


Ralph

unread,
Oct 7, 2008, 12:24:59 PM10/7/08
to

"Eduardo" <m...@mm.com> wrote in message news:gcdq8d$vbo$1...@aioe.org...

> It seems that my assumption that the form's resources are stored as normal
> resources in the exe is wrong.
>
> I run this sample:
> http://allapi.mentalis.org/apilist/7ECF27320393EB56B2A2F1406BA51BC9.html
>
> And if I add images with a resorce file added to the project, they appear
in
> the list of resources, but if I add images to an Imagelist control placed
on
> a form, they don't appear in the list.
>

Property Bags and other controls (ImageList, ...), Forms, DataEnvironment,
design-time tools. store their data as a single Binary String. This data
store has always been referred to as 'resources'. That's where the "rx"
comes from in ".frx" and ".drx", etc. Whether these strings are stored in
the Data segment or as a Custom Resource has never been of particular
importance.

Your discovery that they are apparently not stored as 'normal' resources in
not surprising in that these items or elements have always been difficult to
mine compared to other designers in other platforms (eg. VC++).

Even if we knew exactly where a Form or Control stored this data, at runtime
we would still have to have some information on 'tags' and 'identifiers' to
make sense out of the data. So you are back to square one How do you
retrieve those identifiers - as most 'identifiers' are lost on compilations
(becoming merely an address).

[In essence that is exactly what the Write/Read Property procedures are
doing. Preserving Property Tags as literal strings within your program.]

However, Schmidt has provided a simple work around - create your own
design-time control to specifically store this data to make it availble to
your control. What better time to record this information than at
design-time?

-ralph


Eduardo

unread,
Oct 7, 2008, 1:39:20 PM10/7/08
to
"Ralph" <nt_cons...@yahoo.com> escribió en el mensaje
news:uz$AXrJKJ...@TK2MSFTNGP03.phx.gbl...

> However, Schmidt has provided a simple work around - create your own
> design-time control to specifically store this data to make it availble to
> your control. What better time to record this information than at
> design-time?

I answered to that.


Eduardo

unread,
Oct 7, 2008, 1:50:06 PM10/7/08
to
"Eduardo" <m...@mm.com> escribió en el mensaje news:gcg6us$jd5$1...@aioe.org...

But I think I'll finally do something like that, not with another control,
but with a property of the existing control to flag if the images are global
or only for this form.

Anyway, I also think that may be I already found the solution. In the other
newsgroup (microsoft.public.vb.general.discussion) I started a thread on
this subject and when answering to expvb I realized how I can know what is
the control instance that will load first (if the compilation is in the same
order).


Eduardo

unread,
Oct 7, 2008, 2:07:48 PM10/7/08
to
"Eduardo" <m...@mm.com> escribió en el mensaje news:gcg7go$lt3$1...@aioe.org...

Now I'm thinking that another control could also be an option.

Thanks Schmidt for the idea and also Ralph for making me think again about
that.

I'll think about it. I have time, this is not something that I have to do
now, but I'll do sometime later.
But as I saw that there were problems, I posted the question. Now I have
more clarity. Thanks.


0 new messages