Solved

VB6-Class Builder ActiveX -Hierarchy

Posted on 2000-04-11
6
157 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access Search and Replace Using VBA 6 105
Using "ScreenUpdating" 6 86
which modules are active in VB6 project? 6 57
VB6 common control 6 sp6 object library not registerd 3 65
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

751 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