[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Modifying class attributes

Jason Keats

7/22/2011 6:19:00 AM

If you use Notepad to look at a typical class file you will see something
like:

VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "MyClassName"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit


However, I've just learned (because I don't get out much) that if

Attribute VB_GlobalNameSpace = True
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True

then you don't need to instantiate the class before use.

So, rather than

Dim o As MyClassName
Set o = New MyClassName
o.MyProcedureName
Set o = Nothing

it is then possible to just use

MyClassName.MyProcedurename

In other words it becomes what is known as a shared or static class.

It seems there are some benefits to using the above, rather than .bas
modules.

What is the downside?

Can those attributes be modified from the IDE?


8 Answers

Jason Keats

7/22/2011 6:22:00 AM

0

Sorry, the above was meant to be addressed from me.

Jason


Dee Earley

7/22/2011 10:33:00 AM

0

On 22/07/2011 07:18, news.bigpond.com wrote:
> If you use Notepad to look at a typical class file you will see something
> like:
>
> VERSION 1.0 CLASS
> BEGIN
> MultiUse = -1 'True
> Persistable = 0 'NotPersistable
> DataBindingBehavior = 0 'vbNone
> DataSourceBehavior = 0 'vbNone
> MTSTransactionMode = 0 'NotAnMTSObject
> END
> Attribute VB_Name = "MyClassName"
> Attribute VB_GlobalNameSpace = False
> Attribute VB_Creatable = True
> Attribute VB_PredeclaredId = False
> Attribute VB_Exposed = False
> Option Explicit
>
>
> However, I've just learned (because I don't get out much) that if
>
> Attribute VB_GlobalNameSpace = True
> Attribute VB_Creatable = False
> Attribute VB_PredeclaredId = True
>
> then you don't need to instantiate the class before use.
>
> So, rather than
>
> Dim o As MyClassName
> Set o = New MyClassName
> o.MyProcedureName
> Set o = Nothing
>
> it is then possible to just use
>
> MyClassName.MyProcedurename
>
> In other words it becomes what is known as a shared or static class.
>
> It seems there are some benefits to using the above, rather than .bas
> modules.
>
> What is the downside?

It only works for ActiveX DLL/EXE projects from anything that references
it (IE, not in the same project)

> Can those attributes be modified from the IDE?

Set the Instancing property to 6, GlobalMultiUse.

Note that editing the file may go behind VB's back and allow it to work
for normal projects, as that property isn't available to non AX projects.

--
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk...

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

Jason Keats

7/22/2011 1:27:00 PM

0

Deanna Earley wrote:
> On 22/07/2011 07:18, news.bigpond.com wrote:
>> If you use Notepad to look at a typical class file you will see something
>> like:
>>
>> VERSION 1.0 CLASS
>> BEGIN
>> MultiUse = -1 'True
>> Persistable = 0 'NotPersistable
>> DataBindingBehavior = 0 'vbNone
>> DataSourceBehavior = 0 'vbNone
>> MTSTransactionMode = 0 'NotAnMTSObject
>> END
>> Attribute VB_Name = "MyClassName"
>> Attribute VB_GlobalNameSpace = False
>> Attribute VB_Creatable = True
>> Attribute VB_PredeclaredId = False
>> Attribute VB_Exposed = False
>> Option Explicit
>>
>>
>> However, I've just learned (because I don't get out much) that if
>>
>> Attribute VB_GlobalNameSpace = True
>> Attribute VB_Creatable = False
>> Attribute VB_PredeclaredId = True
>>
>> then you don't need to instantiate the class before use.
>>
>> So, rather than
>>
>> Dim o As MyClassName
>> Set o = New MyClassName
>> o.MyProcedureName
>> Set o = Nothing
>>
>> it is then possible to just use
>>
>> MyClassName.MyProcedurename
>>
>> In other words it becomes what is known as a shared or static class.
>>
>> It seems there are some benefits to using the above, rather than .bas
>> modules.
>>
>> What is the downside?
>
> It only works for ActiveX DLL/EXE projects from anything that references
> it (IE, not in the same project)
>
>> Can those attributes be modified from the IDE?
>
> Set the Instancing property to 6, GlobalMultiUse.
>
> Note that editing the file may go behind VB's back and allow it to work
> for normal projects, as that property isn't available to non AX projects.
>

Thanks, Dee, for your reply. Yes, I'm talking about changing a normal
class in a regular .exe project.

I came across this in a sample project (by Bob Riemersma) I recently
downloaded - and was surprised. I can't remember seeing this done before.

I was wondering if others use this "feature". My guess is that it must
be achieved via Notepad.

ralph

7/22/2011 4:17:00 PM

0

On Fri, 22 Jul 2011 23:27:28 +1000, Jason Keats
<jkeats@melbpcDeleteThis.org.au> wrote:

>Deanna Earley wrote:
>> On 22/07/2011 07:18, news.bigpond.com wrote:
>>> If you use Notepad to look at a typical class file you will see something
>>> like:
>>>
>>> VERSION 1.0 CLASS
>>> BEGIN
>>> MultiUse = -1 'True
>>> Persistable = 0 'NotPersistable
>>> DataBindingBehavior = 0 'vbNone
>>> DataSourceBehavior = 0 'vbNone
>>> MTSTransactionMode = 0 'NotAnMTSObject
>>> END
>>> Attribute VB_Name = "MyClassName"
>>> Attribute VB_GlobalNameSpace = False
>>> Attribute VB_Creatable = True
>>> Attribute VB_PredeclaredId = False
>>> Attribute VB_Exposed = False
>>> Option Explicit
>>>
>>>
>>> However, I've just learned (because I don't get out much) that if
>>>
>>> Attribute VB_GlobalNameSpace = True
>>> Attribute VB_Creatable = False
>>> Attribute VB_PredeclaredId = True
>>>
>>> then you don't need to instantiate the class before use.
>>>
>>> So, rather than
>>>
>>> Dim o As MyClassName
>>> Set o = New MyClassName
>>> o.MyProcedureName
>>> Set o = Nothing
>>>
>>> it is then possible to just use
>>>
>>> MyClassName.MyProcedurename
>>>
>>> In other words it becomes what is known as a shared or static class.
>>>
>>> It seems there are some benefits to using the above, rather than .bas
>>> modules.
>>>
>>> What is the downside?
>>
>> It only works for ActiveX DLL/EXE projects from anything that references
>> it (IE, not in the same project)
>>
>>> Can those attributes be modified from the IDE?
>>
>> Set the Instancing property to 6, GlobalMultiUse.
>>
>> Note that editing the file may go behind VB's back and allow it to work
>> for normal projects, as that property isn't available to non AX projects.
>>
>
>Thanks, Dee, for your reply. Yes, I'm talking about changing a normal
>class in a regular .exe project.
>
>I came across this in a sample project (by Bob Riemersma) I recently
>downloaded - and was surprised. I can't remember seeing this done before.
>
>I was wondering if others use this "feature". My guess is that it must
>be achieved via Notepad.

Also IIRC it also essentially makes the Class name an "inherent
object" similar to using a Form name, or using a "As New" declaration.
So you are adding the extra check for "Nothing" with every call.

-ralph

Jason Keats

7/22/2011 4:25:00 PM

0

Mayayana wrote:
> I don't see what the advantage is. If I want to
> use a class for the length of program run then maybe
> I *could* use the method you describe, but who
> cares, really?

That's what I want to know. Does anyone care? Is it useful? How does it
compare with just using a .bas module? Are there any disadvantages
compared with a .bas module? Who else knew about it? If so, why didn't
they tell me? <g>

Dee Earley

7/22/2011 4:54:00 PM

0

On 22/07/2011 17:25, Jason Keats wrote:
> Mayayana wrote:
>> I don't see what the advantage is. If I want to
>> use a class for the length of program run then maybe
>> I *could* use the method you describe, but who
>> cares, really?
>
> That's what I want to know. Does anyone care? Is it useful? How does it
> compare with just using a .bas module? Are there any disadvantages
> compared with a .bas module?

modules allow public classes (for API callbacks) whereas classes are
able to declare object WithEvents.
Among others..

--
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk...

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

Mayayana

7/23/2011 2:17:00 AM

0

I don't see what the advantage is. If I want to
use a class for the length of program run then maybe
I *could* use the method you describe, but who
cares, really? I don't find it especially burendsome to
just instantiate the class at startup and release it at
close.


Jason Keats

7/23/2011 2:34:00 AM

0

ralph wrote:
>
> Also IIRC it also essentially makes the Class name an "inherent
> object" similar to using a Form name, or using a "As New" declaration.
> So you are adding the extra check for "Nothing" with every call.

My tests indicate that's absolutely correct.

Modifying a classes attributes (ie inverting the values of
VB_GlobalNameSpace, VB_Creatable, VB_PredeclaredId) just gives you a
class that can be treated exactly like a Form, but without the GUI.

Thank you all for your time.