static class data in ActiveX DLLs? 
Author Message
 static class data in ActiveX DLLs?

Hello-

I am trying to implement a class in an ActiveX DLL that
makes use of static class data.

For some reason, the static class data does not work
as documented.   According to the Component Tools Guide,
in the section titled "Standard Modules vs. Class Modules",

  there may be occasions when you want a data member to
  be shared among all objects created from a class module.

I have tried to implement this according to the instructions in
this section, and cannot make it work.

The following is my code from my ActiveX DLL project:

In module.bas

  Public gstrTestGlobal As String

In class.cls

  Property Get TestGlobal() As String
     TestGlobal = Module1.gstrTestGlobal
  End Property

  Property Let TestGlobal(tg As String)
     gstrTestGlobal = tg
  End Property

And, here is how I test it.  I have a single form in a separate
Standard EXE project.  It contains two CommandButton
controls.  Here are the Click events from these two controls:

  Private Sub Command1_Click()
      Dim a As Project1.Class1

      Set a = New Project1.Class1

      a.TestGlobal = "Test Global"

      MsgBox a.TestGlobal

      Set a = Nothing
  End Sub

  Private Sub Command2_Click()
      Dim a As Project1.Class1

      Set a = New Project1.Class1

      MsgBox a.TestGlobal

      Set a = Nothing
  End Sub

I would expect that after clicking on CommandButton1, that
the message box displayed by CommandButton2 would
contain "Test Global".  However, it does not; it is blank.

Some additional points:

  * The message box in the Click event for CommandButton1
    works as expected, and contains "Test Global".

  * For some reason, the global gstrTestGlobal is not seen
    when I browse the type library either with the Object Browser
    in Visual Basic, or with OLE View.

Thanks for any help,
Kevin Samborn
--

Kevin Samborn



Fri, 14 Mar 2003 03:00:00 GMT  
 static class data in ActiveX DLLs?

It's the ...

Quote:
>       Set a = Nothing

Once the last instance of your class is destroyed, all data will go with it.
You need to keep at least one instance loaded if you want that static data.

'==========Try.....
Option Explicit

Private obj As class1

Private Sub Form_Load()
   Set obj = New class1
End Sub

Private Sub Form_Unload(Cancel As Integer)
   Set obj = Nothing
End Sub

Quote:
>   Private Sub Command1_Click()
>       Dim a As Project1.Class1

>       Set a = New Project1.Class1

>       a.TestGlobal = "Test Global"

>       MsgBox a.TestGlobal

>       Set a = Nothing
>   End Sub

>   Private Sub Command2_Click()
>       Dim a As Project1.Class1

>       Set a = New Project1.Class1

>       MsgBox a.TestGlobal

>       Set a = Nothing
>   End Sub

'==========


- Show quoted text -

Quote:
> Hello-

> I am trying to implement a class in an ActiveX DLL that
> makes use of static class data.

> For some reason, the static class data does not work
> as documented.   According to the Component Tools Guide,
> in the section titled "Standard Modules vs. Class Modules",

>   there may be occasions when you want a data member to
>   be shared among all objects created from a class module.

> I have tried to implement this according to the instructions in
> this section, and cannot make it work.

> The following is my code from my ActiveX DLL project:

> In module.bas

>   Public gstrTestGlobal As String

> In class.cls

>   Property Get TestGlobal() As String
>      TestGlobal = Module1.gstrTestGlobal
>   End Property

>   Property Let TestGlobal(tg As String)
>      gstrTestGlobal = tg
>   End Property

> And, here is how I test it.  I have a single form in a separate
> Standard EXE project.  It contains two CommandButton
> controls.  Here are the Click events from these two controls:

>   Private Sub Command1_Click()
>       Dim a As Project1.Class1

>       Set a = New Project1.Class1

>       a.TestGlobal = "Test Global"

>       MsgBox a.TestGlobal

>       Set a = Nothing
>   End Sub

>   Private Sub Command2_Click()
>       Dim a As Project1.Class1

>       Set a = New Project1.Class1

>       MsgBox a.TestGlobal

>       Set a = Nothing
>   End Sub

> I would expect that after clicking on CommandButton1, that
> the message box displayed by CommandButton2 would
> contain "Test Global".  However, it does not; it is blank.

> Some additional points:

>   * The message box in the Click event for CommandButton1
>     works as expected, and contains "Test Global".

>   * For some reason, the global gstrTestGlobal is not seen
>     when I browse the type library either with the Object Browser
>     in Visual Basic, or with OLE View.

> Thanks for any help,
> Kevin Samborn
> --

> Kevin Samborn



Fri, 14 Mar 2003 03:00:00 GMT  
 static class data in ActiveX DLLs?

Thank you very much.  One more question:


Quote:
> It's the ...
> >       Set a = Nothing

> Once the last instance of your class is destroyed, all data will go with
it.
> You need to keep at least one instance loaded if you want that static

data.

Is there any way to instantiate a global instance of the class from within
the DLL itself?  So clients of the DLL do not have to worry about creating
a special instance, and the process can be made automatic?

Thanks again,
Kevin



Fri, 14 Mar 2003 03:00:00 GMT  
 static class data in ActiveX DLLs?

Look at the help regarding "Global Multiuse" objects.... I believe this is
what you're looking for.


Quote:
> Thank you very much.  One more question:



> > It's the ...
> > >       Set a = Nothing

> > Once the last instance of your class is destroyed, all data will go with
> it.
> > You need to keep at least one instance loaded if you want that static
> data.

> Is there any way to instantiate a global instance of the class from within
> the DLL itself?  So clients of the DLL do not have to worry about creating
> a special instance, and the process can be made automatic?

> Thanks again,
> Kevin



Fri, 14 Mar 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. data source class in ActiveX DLL vs EXE -- URGENT

2. Static class data

3. How to call one VB class module method from another class in an ActiveX dll

4. static classes and methods

5. Static Class and Variable

6. creating static classes?

7. Newbie: OCX,ActiveX,DLL,Class

8. Static class module in VBA

9. Calling methods across classes within ActiveX-Dll

10. Q: Memeroyuse of Classes in ActiveX-Dll

11. Declaring an object in a Class from an ActiveX or DLL referenced

12. Help with ActiveX dll class objects not terminating correctly (VB5)

 

 
Powered by phpBB® Forum Software