[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

VB6-Class Builder ActiveX -Hierarchy

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
RDurando
Asked:
RDurando
  • 4
  • 2
1 Solution
 
caraf_gCommented:
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
 
caraf_gCommented:
Public Sub DisplayTheHelloConstant()
  MsgBox (mobjMyLibrary.HelloConstant)
End Sub

0
 
RDurandoAuthor Commented:
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
Independent Software Vendors: 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!

 
caraf_gCommented:
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
 
caraf_gCommented:
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
 
RDurandoAuthor Commented:
Thanks very much for your help
Berto;-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now