Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help: Creating an Object Model 2

Status
Not open for further replies.

RobSchultz

Programmer
Jun 1, 2000
444
US
Hello all,

I've been trying to figure out how to create parent/child relationships in a class for a couple of days but just can't figure it out. How do I create the ability to do something such as...
Code:
Object.Parent.Property

Right now all my code is
  Object.FontBold = or Object.FontColor = 
I would like to have
  Object.Font.Bold or Object.Font.Color =
I'm thinking it has to do something with Property Set but I don't understand the process.

TIA,
Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Give your Object object a Font property and an mFont member variable. The Font property sets or returns a Font object into/from mFont. That font object then has Bold and Color properties of its own.

In the syntax:
Object.Font.Bold
First the Object returns its Font property, a Font object. Then the Font object returns its Bold property, a Boolean value. Rick Sprague
 
Rick

Thanks for the reply. I find I must ask you for a small code sample. Thanks to your response I believe I understand the concept behind doing this but I don't have the syntax.

Thanks, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Hi,
Try this out. Modify as needbe.

'Definition of Class: AFont
Option Explicit
Dim MyColor As Long
Dim MyBold As Boolean

Public Property Get Bold() As Boolean
Bold = MyBold
End Property

Public Property Let Bold(ByVal vNewValue As Boolean)
MyBold = vNewValue
End Property

Public Property Get Color() As Long
Color = MyColor
End Property

Public Property Let Color(ByVal vNewValue As Long)
MyColor = vNewValue
End Property


'Definition of Class: AnObject
Option Explicit
Dim MyFont As AFont

Public Property Get Font() As AFont
Set Font = MyFont
End Property

Public Property Let Font(ByVal vNewValue As AFont)
Set MyFont = vNewValue
End Property


'Implementation of Classes.
Dim MyObject As AnObject
Dim MyFont As AFont

Set MyObject = New MyObj
Set MyFont = New AFont
MyObject.Font = MyFont
MyObject.Font.Color = 10
MyObject.Font.Bold = True

I hope this helps.

Have a good one!
BK
 
Ahhhhhh! *:->*

Now I get it! Its so obvious (once I was dragged kicking and screaming to the proper conclusion). Thanks to both of you for your help.

Regards, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top