Solved

VB6-Class Builder ActiveX -Hierarchy

Posted on 2000-04-11
6
158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

617 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