ralph
7/22/2011 4:17:00 PM
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