Solved

VB6-Class Builder ActiveX -Hierarchy

Posted on 2000-04-11
6
151 Views
Last Modified: 2010-05-02
Hi, I have a Single Class : TheLibrary.MyLibrary.

In MyLibrary I have several properties and functions.

TheLibrary
  - MyLibrary
    o Many properties (say 20)
    > Many methods (say 50)

- Denotes Class
o Denotes Property
> Denotes Method



Now I want create a class hierarchy, as I only have a single
class with a flat structure of properties and functions.

Let say I have a property called HelloConstant.

ie:  TheLibrary.MyLibrary.HelloConstant : String;

I now want to add a sub class called Messages
  TheLibrary.MyLibrary.Messages
  which I have done using the Classbuilder

so my tree view looks like:

TheLibrary
  - MyLibrary
    o All my other properties...
    o HelloConstant
    > All my other methods
    - Messages
      > DisplayTheHelloConstant

- Denotes Class
o Denotes Property
> Denotes Method


My sub for DisplayTheHelloConstant is:

Public Sub DisplayTheHelloConstant()
  MsgBox (HelloConstant)
End Sub

which does not work because the Messages.cls doesn't seem to be able
to access the MyLibrary class property HelloConstant.

I want the client to run code that looks like this:

  MyLibraryObj.HelloConstant = "Hello world"
  MyLibraryObj.Messages.DisplayTheHelloConstant

But I cant figure out what I should do for the DisplayTheHelloConstant function..

Thanks
Berto.
0
Comment
Question by:RDurando
  • 4
  • 2
6 Comments
 
LVL 10

Expert Comment

by:caraf_g
ID: 2703470
Assuming that MyLibrary and Messages are in the same project

In Messages you can declare a Friend property


In general declarations:
Private mobjMyLibrary As MyLibrary

Friend Property Set FriendLibrary(objNew as MyLibrary)

Set mobjMyLibrary = objNew

End Property

When your MyLibrary instantiates the Messages Object, follow that immediately with
Set Messages.FriendLibrary = Me

Once you've done that, your Messages class can access the HelloConstant variable of its parent MyLibrary object by FriendLibrary.HelloConstant

And because the property FriendLibrary is defined as a Friend property, code outside the project cannot access it.

Hope this helps!

Pino
0
 
LVL 10

Accepted Solution

by:
caraf_g earned 40 total points
ID: 2703474
Public Sub DisplayTheHelloConstant()
  MsgBox (mobjMyLibrary.HelloConstant)
End Sub

0
 

Author Comment

by:RDurando
ID: 2703542
Pino : you're loosing me...

I'm sure you know what you are doing, but I can't see what it is at the moment.


Let me try again :

This is my DLL:
==============================
TheLibrary
  - MyLibrary
    o All my other properties...
    o HelloConstant
    > All my other methods
    - Messages
      > DisplayTheHelloConstant

- Denotes Class
o Denotes Property
> Denotes Method


This is my Client Application:
==============================
Dim MyLibraryObj As MyLibrary

Private Sub Form_Load()
  Set MyLibraryObj = New MyLibrary
End Sub

Private Sub Command5_Click()
  MyLibraryObj.HelloConstant = "Hello world"
  MyLibraryObj.Messages.DisplayTheHelloConstant <---This line Does not Run.
End Sub


This line does not run because I have not setup my DLL Correctly.

In my DLL project I have 2 class modules:
MyLibrary
Messages



MyLibrary looks like this:
==============================
'local variable(s) to hold property value(s)
Private mvarHelloConstant As String 'local copy
Private mvarMessages As Messages

Public Property Get Messages() As Messages
    Set Messages = mvarMessages
End Property

Public Property Set Messages(vData As Messages)
    Set mvarMessages = vData
End Property

Private Sub Class_Terminate()
    Set mvarMessages = Nothing
End Sub

Public Property Let HelloConstant(ByVal vData As String)
    mvarHelloConstant = vData
End Property

Public Property Get HelloConstant() As String
    HelloConstant = mvarHelloConstant
End Property

Private Sub Class_Initialize()
  Set mvarMessages = New Messages
End Sub


Messages looks like this:
==============================
Public Sub DisplayTheHelloConstant()
'  MsgBox (???.HelloConstant)
End Sub

Private Sub Class_Initialize()
???
End Sub

Help...
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Expert Comment

by:caraf_g
ID: 2703586
MyLibrary looks like this:
==============================
'local variable(s) to hold property value(s)
Private mvarHelloConstant As String 'local copy
Private mvarMessages As Messages

Public Property Get Messages() As Messages
    Set Messages = mvarMessages
End Property

Public Property Set Messages(vData As Messages)
    Set mvarMessages = vData
End Property

Private Sub Class_Terminate()
    Set mvarMessages = Nothing
End Sub

Public Property Let HelloConstant(ByVal vData As String)
    mvarHelloConstant = vData
End Property

Public Property Get HelloConstant() As String
    HelloConstant = mvarHelloConstant
End Property

Private Sub Class_Initialize()
    Set mvarMessages = New Messages
    Set mvarMessages.FriendLibrary = Me
End Sub


Messages looks like this:
==============================
Private mobjMyLibrary As MyLibrary
Friend Property Set FriendLibrary(objNew As MyLibrary)
    Set mobjMyLibrary = objNew
End Property
Public Sub DisplayTheHelloConstant()
    MsgBox (mobjMyLibrary.HelloConstant)
End Sub

0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2703601
Or, even better:

MyLibrary looks like this:
==============================
'local variable(s) to hold property value(s)
Private mvarHelloConstant As String 'local copy
Private WithEvents mvarMessages As Messages

Public Property Get Messages() As Messages
    Set Messages = mvarMessages
End Property

Public Property Set Messages(vData As Messages)
    Set mvarMessages = vData
End Property

Private Sub Class_Terminate()
    Set mvarMessages = Nothing
End Sub

Public Property Let HelloConstant(ByVal vData As String)
    mvarHelloConstant = vData
End Property

Public Property Get HelloConstant() As String
    HelloConstant = mvarHelloConstant
End Property

Private Sub Class_Initialize()
    Set mvarMessages = New Messages
End Sub

Private Sub mvarMessages_GetHelloConstant(strConstant As String)
    strConstant = mvarHelloConstant
End Sub



Messages looks like this:
==============================
Public Event GetHelloConstant(strConstant As String)
Public Sub DisplayTheHelloConstant()
    Dim strConstant As String
    RaiseEvent GetHelloConstant(strConstant)
    MsgBox strConstant
End Sub
0
 

Author Comment

by:RDurando
ID: 2703640
Thanks very much for your help
Berto;-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now