home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Power Pack / Visual_Basic4_Power_Pack.bin / vb4files / dbawarco / company.cls < prev    next >
Encoding:
Text File  |  1996-11-20  |  2.2 KB  |  87 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Company"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = True
  8. Option Explicit
  9.  
  10. 'Private pvtPersonsCollection As New Persons
  11. Private pvtPersonsCollection As New DBAwareCollection
  12.  
  13.  
  14.  
  15. Public Function TableName() As String
  16.     TableName = "Company"
  17. End Function
  18.  
  19. Public Function EmptyPersons() As Variant
  20. ' Return an emptied Persons collection
  21. '   (handy when wanting to begin processing the Company
  22. '   after having already done some things with it)
  23.  
  24.     Set pvtPersonsCollection = Nothing
  25.     Set pvtPersonsCollection = New DBAwareCollection
  26.  
  27.     Set EmptyPersons = Persons()
  28. End Function
  29.  
  30. Public Function ObjectType() As String
  31.     ObjectType = "Company"
  32. End Function
  33.  
  34. Public Function Persons(Optional ByVal ObjectID As Variant) As Variant
  35. ' Returns a DBAwareCollection of Person objects which are
  36. '   contained by this Company object,
  37. ' or
  38. ' Returns a Person object whose ObjectID matches the ObjectID
  39. '   parameter.
  40.  
  41.     Dim tempNewPerson As New Person
  42.  
  43. ' check for need to populate the collection from the database
  44.     If Not pvtPersonsCollection.DatabaseHasBeenReferenced Then
  45.         pvtPersonsCollection.SetDatabaseParameters _
  46.             Database:=CompanyDatabase, _
  47.             OrderByClause:="LastName ASC, FirstName ASC"
  48.  
  49.         Set pvtPersonsCollection = _
  50.             pvtPersonsCollection.InstantiateFromDatabase( _
  51.                 Parent:=Me, _
  52.                 SampleObject:=tempNewPerson)
  53.     End If
  54.     
  55. ' check for a request for a specific Person
  56.     If Not IsMissing(ObjectID) Then
  57.         Set Persons = pvtPersonsCollection.Item(ObjectID)
  58.  
  59. ' else, return the entire collection
  60.     Else
  61.         Set Persons = pvtPersonsCollection
  62.     End If
  63. End Function
  64. Public Function AddPerson(Optional ByVal Item As Variant, Optional ByVal Parent As Variant) As DBAwareCollection
  65. ' Return a Person, added to my pvtPersonsCollection
  66. '   (just a wrapper method for Persons.Add)
  67.  
  68.     Set AddPerson = Me.Persons.Add( _
  69.         Item:=Item, _
  70.         Parent:=Me)
  71. End Function
  72.  
  73.  
  74.  
  75. Private Sub Class_Initialize()
  76.     Set pvtPersonsCollection = Nothing
  77. End Sub
  78.  
  79.  
  80.  
  81. Public Property Get ObjectID() As Long
  82.     ObjectID = 1
  83. End Property
  84.  
  85.  
  86.  
  87.